How to write a loop which increases two variables at the same time

I could write a single loop which increased two variables, i and j, by one each iteration. I thought nested loops would work, I couldn't get it to increase both variables by the same amount for each iteration. C4 and R4 are just arbitrary row/column indexing numbers, as I am trying to search diagonals of a matrix.
for i=r4+1:8
for j=c4+1:8

 Respuesta aceptada

You can do this as follow
for m=1:00
for n=1:100
i = i+1;
j = j+1;
i and j increase by one after each iteration.

1 comentario

Thanks! I thought of a different way to do it, but that works too.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Preguntada:

el 30 de Abr. de 2018

Comentada:

el 30 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by