use matrix with while loop

1 view (last 30 days)
Volkan Yangin
Volkan Yangin on 5 Jan 2016
Answered: Image Analyst on 5 Jan 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?

Answers (1)

Image Analyst
Image Analyst on 5 Jan 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.

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!