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

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 4 月 30 日

0 投票

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 件のコメント

Bobby Bowes
Bobby Bowes 2018 年 4 月 30 日
Thanks! I thought of a different way to do it, but that works too.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by