if greater than in for loop

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

 Accepted Answer

for k = 1:length(seven)
if seven(k) > 100
seven(k) = seven(k) - 25 ;
end
end

More Answers (1)

seven=(seven>100).*(seven-25)+(seven<=100).*seven;

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 26 Jun 2020

Commented:

on 26 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!