How to find the position of specific entry in a Matrix?
조회 수: 35 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
2018년 3월 8일
A = [3 2 1;3 1 2;2 3 1];
[r, c] = find(A.' == 2);
output = [c, r];
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!