If-statements won't break when conditions aren't met
Mostrar comentarios más antiguos
Hi there!
I am working on a mainscript in Matlab and I have troubles with determining why my code doesn't break when it does not meet the conditions that I have placed within the if statement. Anyone who has got an idea of this?
I hope there are someone out there who has an answer for this!
Best regards
Kristian
2 comentarios
Walter Roberson
el 4 de Mayo de 2015
James Tursa
el 5 de Mayo de 2015
@Kristian: It is an abuse of this site and a disservice to the readers and contributors for you to edit out the content of your question after you have received answers.
Respuesta aceptada
Más respuestas (1)
James Tursa
el 4 de Mayo de 2015
Editada: James Tursa
el 4 de Mayo de 2015
This line does no do what you think it does:
if beamLength < positions(:) | positions(:) < 0 | ~isnan(positions)
If positions is a vector, then beamLength < positions(:) will be a vector result, not a scalar result. So using it as the argument to the if test isn't appropriate. Maybe you meant this instead?
if any(beamLength < positions(:)) || any(positions(:) < 0) || any(isnan(positions(:)))
Similar comments apply to your other if tests as well.
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!