use matrix with while loop

1 visualización (últimos 30 días)
Volkan Yangin
Volkan Yangin el 5 de En. de 2016
Respondida: Image Analyst el 5 de En. de 2016
n_motor=[150 200 250 300 ...] etc and vites_TASIT_1=[0 0 0 0 6 6 6 ...] etc. n_motor calculated by vites_TASIT_1.
for i=1:1:1180;
if vites_TASIT_1(i,1)>0;
if n_motor_TASIT_1(i)<750;
while n_motor_TASIT_1(i)>750;
vites_TASIT_1(i,1)=vites_TASIT_1(i,1)-1;
end
end
else
end
end
i can't make this loop. what are the mistakes?

Respuestas (1)

Image Analyst
Image Analyst el 5 de En. de 2016
You only get into the "if" if n_motor_TASIT_1(i) is less than 750, but your while only executes if it's more than 750. Those are contradictory, so if it gets inside the "if" it will never execute the "while".
Plus your while loop never changes n_motor_TASIT_1(i) so even if it did get into the while loop, it would never get out of it. You have an infinite loop because you do not have a secondary fail-safe condition where you check the number of iterations and bail out if it's unreasonably large, and no way to ever change the single condition you are checking.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by