Negating negative values in a matrix using for and if loops in Matlab
Show older comments
Hey I'm new here so sorry if this question has already been answered. I couldn't find out anything about it.
The problem: As it stands, I'm trying to write a program in MATLAB that takes a list of values input by the user and runs them through various functions. I don't want it to accept negative values at all.
What I have so far:
m = input('Please enter values as a row vector \n');
n = length(m);
for k = 1:n
if m(k) > 0;
m(k) = m(k);
else m <= 0;
m(k) = 0;
end
end
m
Any advice would be appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!