How to Keep Nested For Loop Indexes From Equaling Each Other
Mostrar comentarios más antiguos
If I have two nested for loops like this, is there a way to skip the iteration where i=j?
for i=1:50
for j=1:50
code
end
end
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 5 de Mayo de 2020
for i=1:50
for j=[1:i-1,i+1:50]
or
for i=1:50
for j=setdiff(1:50, i)
1 comentario
Thomas Schoenstein
el 5 de Mayo de 2020
per isakson
el 5 de Mayo de 2020
for ii=1:50
for jj=1:50
if not(jj==ii)
code
end
end
end
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!