MATLAB Answers

if greater than in for loop

8 views (last 30 days)
Eliana Juarez
Eliana Juarez on 26 Jun 2020
Commented: Eliana Juarez on 26 Jun 2020
using a for loop and if statement, i need to subtract 25 from each element in a vector called "seven" that is greater than 100.
here is my code, but when i run it i get the original values of all elements in seven. how can i fix this?
for k = seven
if k > 100
k - 25
else
k + 0
end
end

  0 Comments

Sign in to comment.

Accepted Answer

KSSV
KSSV on 26 Jun 2020
for k = 1:length(seven)
if seven(k) > 100
seven(k) = seven(k) - 25 ;
end
end

  1 Comment

Eliana Juarez
Eliana Juarez on 26 Jun 2020
Thank you so much!

Sign in to comment.

More Answers (1)

Rafael Hernandez-Walls
Rafael Hernandez-Walls on 26 Jun 2020
seven=(seven>100).*(seven-25)+(seven<=100).*seven;

  0 Comments

Sign in to comment.

Products


Release

R2020a