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

7 visualizaciones (últimos 30 días)
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....

Respuesta aceptada

Sara
Sara el 10 de Mayo de 2014
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?

Más respuestas (1)

Star Strider
Star Strider el 10 de Mayo de 2014
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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by