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 个评论
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.
采纳的回答
更多回答(1 个)
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
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!