how to stop from running a program whenever any of the element become zero or gets negative?

i have a matrix A=rand(m,n); B=1-A; so when B is running in a loop for 100 times i want to end the matrix once any of the element of B becomes zero.
plz plz help me....

1 Comment

B will never be exactly 0 since A will never be exactly 1, at least probably not in your lifetime.

Sign in to comment.

 Accepted Answer

If you want to exit the loop, you can do:
if(ismember(0,B))
break
end
If there is code after the loop, that part will be executed though. Do you have code after the loop that you do NOT want to execute?

More Answers (1)

Categories

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

Tags

Asked:

on 10 May 2014

Commented:

on 11 May 2014

Community Treasure Hunt

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

Start Hunting!