Hi, I have the following code:
for m=1:10
for n=1:sz(2)
if(Isingle(m,n)==1)
index1=[m n];
break;
end
end
end
I need to exit from the entire for loop i.e. for m=1:10 and for n=1:sz(2) when any index value is found, i don't know how to do that. can any body help?
Thanks

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 10 de Ag. de 2011

0 votos

[i1 j1] = find(Isingle' == 1, 1, 'first')
OR with loops
for m=1:10
for n=1:sz(2)
if(Isingle(m,n)==1)
index1=[m n];
return
end
end
end

Más respuestas (1)

Friedrich
Friedrich el 10 de Ag. de 2011

4 votos

Hi,
I think you have to use a flag
flag = 0
for m=1:10
for n=1:sz(2)
if(Isingle(m,n)==1)
index1=[m n];
flag = 1
break;
end
end
if flag == 1
break;
end
end

2 comentarios

Friedrich
Friedrich el 10 de Ag. de 2011
Thanks, your are right. fixed it.
Tong Zhao
Tong Zhao el 26 de Jun. de 2022
Thanks from 2022, very educational.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Ag. de 2011

Comentada:

el 26 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by