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

조회 수: 35 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by