use matrix with while loop

1 回表示 (過去 30 日間)
Volkan Yangin
Volkan Yangin 2016 年 1 月 5 日
回答済み: Image Analyst 2016 年 1 月 5 日
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?

回答 (1 件)

Image Analyst
Image Analyst 2016 年 1 月 5 日
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.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by