Using a WHILE loop for a trial and error solution.

Risposte (1)

Image Analyst
Image Analyst il 1 Mar 2014
Modificato: Image Analyst il 1 Mar 2014
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.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

Joe
il 1 Mar 2014

Modificato:

Joe
il 7 Mar 2014

Community Treasure Hunt

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

Start Hunting!

Translated by