How to find the position of specific entry in a Matrix?

14 ビュー (過去 30 日間)
Ammy
Ammy 2018 年 3 月 8 日
コメント済み: Ammy 2018 年 3 月 9 日
I have a matrix like
A=[3 2 1;3 1 2;2 3 1];
I want to find the position of 2 in each row
I need
1 2
2 3
3 1
which indicates that at first row it is in second column, at second row it is is in third column and at third row it is in first column,
Thanks
  1 件のコメント
Ammy
Ammy 2018 年 3 月 8 日
output =
3 1
1 2
2 3
This indicates the position column wise but i want the position of entry rowwise

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 8 日
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A == 2);
output = [r, c]
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 8 日
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A.' == 2);
output = [c, r];
Ammy
Ammy 2018 年 3 月 9 日
Thank you very much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by