if statement for a matrix
Mostrar comentarios más antiguos
Hi my x-axis is a 1x72 matrix having values from 1 to 72.
y axis values are again 1x72 matrix having data values.
I want the "if loop" to go on for only those x values which are between 10 and 25, and plot x vs y for only those selected values (y axis data values corresponding to the values between 10 to 25). Could you please evaluate my code.
for i = 1:length(x)
if (x>10) && (x<25)
plot(x,y)
end
end
Respuesta aceptada
Más respuestas (2)
Alex Mcaulley
el 11 de Mzo. de 2019
You don't need the loop, just using logical indexing:
plot(x(x>10&x<25),y(x>10&x<25))
Darpan Verma
el 11 de Mzo. de 2019
0 votos
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!