Using a WHILE loop for a trial and error solution.

回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 1 日
編集済み: Image Analyst 2014 年 3 月 1 日

0 投票

You can't use this invalid syntax:
(0.05*Cm)<Pn<(0.05*abs(Cm))
You have to do it as two separate comparisons:
(0.05*Cm)<Pn && Pn <(0.05*abs(Cm))
Fix that and try it again.
Also, you tagged it as "infinite loop" - that's why robust code (like I write) always has a failsafe in there. For example you could have a loop counter and if it exceeds some number that you expect it to never exceed, bail out of the loop
counter = 1;
while someCondition
% code
counter = counter + 1;
if counter >= 5000 % Some big number
break; % Fail safe - something went wrong so bail out!!!
end
end % of while loop.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

Joe
2014 年 3 月 1 日

編集済み:

Joe
2014 年 3 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by