if greater than in for loop
Show older comments
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
More Answers (1)
Rafael Hernandez-Walls
on 26 Jun 2020
seven=(seven>100).*(seven-25)+(seven<=100).*seven;
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!