Logical condition for a while lopp exits prematureley
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Philip Berg
el 28 de Oct. de 2016
Comentada: Jan
el 28 de Oct. de 2016
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 comentarios
KSSV
el 28 de Oct. de 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.
Respuesta aceptada
Jan
el 28 de Oct. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Downloads en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!