Looping through a Matrix

As of now, I have a 10x10 matrix of twos with 0s and 1s randomly generated in the matrix. I need to index through each component of the matrix based on the value I encounter. Starting at (1,1) and indexing by rows. If it is a 2, I need to add 1 to it and continue to the next row. If it is a 1, I need to switch from indexing by rows to indexing to the columns above it. If it is a 0, I need to switch from indexing by row to indexing to the columns below it. Trying to figure out of to loop through each component of the matrix and switch indexing direction based on the values in the matrix.

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 5 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 5 日

0 投票

mat=randi([0 2],[10,10]); % Just as an example
result=mat+(mat==2)

カテゴリ

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

タグ

質問済み:

2019 年 11 月 5 日

編集済み:

2019 年 11 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by