If-statements won't break when conditions aren't met
Show older comments
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 Comments
James Tursa
on 5 May 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.
Accepted Answer
More Answers (1)
James Tursa
on 4 May 2015
Edited: James Tursa
on 4 May 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.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!