if greater than in for loop
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eliana Juarez
el 26 de Jun. de 2020
Comentada: Eliana Juarez
el 26 de Jun. de 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 comentarios
Respuesta aceptada
KSSV
el 26 de Jun. de 2020
for k = 1:length(seven)
if seven(k) > 100
seven(k) = seven(k) - 25 ;
end
end
Más respuestas (1)
Rafael Hernandez-Walls
el 26 de Jun. de 2020
seven=(seven>100).*(seven-25)+(seven<=100).*seven;
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!