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

 Accepted Answer

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 Comment

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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!