Azzera filtri
Azzera filtri

Logical condition for a while lopp exits prematureley

2 visualizzazioni (ultimi 30 giorni)
Hi, I have this while loop criteria,
while((std(PenPar(:,2),0,1) > 50 && std(PenPar(:,3),0,1) > 50 && std(PenPar(:,4),0,1) > 50) || Stopper==500)
but it stops prematurely; only one of the and terms are satisfied.
Can someone explain me why it is so? Best reagrds
  5 Commenti
KSSV
KSSV il 28 Ott 2016
As stopper is less then 500. This statement counts to 0. If any std out of three is not satisfied then loop will surely stops. You have to check your std.
Philip Berg
Philip Berg il 28 Ott 2016
Ok, so my issue was that I don't want it to stop just because one of the std reaches bellow 50. Which I see, as I verbose the std constantly. Maybe if I specify my problem better. I want all statements to be true for it to stop. All three columns has to have a std bellow 50 for it to stop. Not just one of them. The last verbose is:
Running BigLoop itteration 1365 current st.dev =93.56746 124.6802 50.11569
so there is no way it is something with the std.

Accedi per commentare.

Risposta accettata

Jan
Jan il 28 Ott 2016
while all(std(PenPar(:,2:4),0,1) > 50) || Stopper == 500
does, what you ask for. But this is equivalent to your code, because && has a higher precedence than || . Therefore I'm still convinced, that your code works fine and the loop is not finished too early. Are you sure that the loop is not terminated by the Stopper limit?
  4 Commenti
Philip Berg
Philip Berg il 28 Ott 2016
Haha, thanks for the help! Indeed the error is in the verbose command. How tedious to not notice. Yes I did not expect magic from MATLAB.
Jan
Jan il 28 Ott 2016
:-) Fine. I'm glad that your problem is solved. Have a nice day.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by