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

2 ビュー (過去 30 日間)
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 件のコメント
Image Analyst
Image Analyst 2014 年 5 月 10 日
B will never be exactly 0 since A will never be exactly 1, at least probably not in your lifetime.

サインインしてコメントする。

採用された回答

Sara
Sara 2014 年 5 月 10 日
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?

その他の回答 (1 件)

Star Strider
Star Strider 2014 年 5 月 10 日
Use the any and break functions.
Example:
for k1 = 1:100
A = rand(10);
B = 1-A;
if any(B == 0)
k1
break
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by