Loop which Checks Values of Matrix
Show older comments
M = [2.7 , 1.9 , 0.75 , 0.16 , 0.35]
I have a matrix and I would like it to check each element and replace it with a new number or leave the old one depending on the parameter taken.
if element is bigger than c=1 make new element from formula
and if smaller do nothing with that number
I do not know how difficult or simple it is.
I am just starting my adventure with loops and I am counting on help here
2 Comments
Stephen23
on 2 Jun 2022
"...make new element from formula"
What is the formula?
Accepted Answer
More Answers (1)
M = [2.7 , 1.9 , 0.75 , 0.16 , 0.35];
c = 1;
for ii = 1:numel(M)
if M(ii) > c
M(ii) = % new element from formula
end
end
(assuming the objective was to learn how for loops work)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!