Using a WHILE loop for a trial and error solution.

3 views (last 30 days)
Joe
Joe on 1 Mar 2014
Edited: Joe on 7 Mar 2014
Deleted

Answers (1)

Image Analyst
Image Analyst on 1 Mar 2014
Edited: Image Analyst on 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.

Categories

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

Community Treasure Hunt

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

Start Hunting!