Finding the index of spesific element in a matrix?
조회 수: 726 (최근 30일)
이전 댓글 표시
Lets say we have matrix:
a=[ 2, 3, 5
3, 4, 7
4, 4, 4] ;
I want to know index of a(4) which is the bold 3. This is just an example. I want to learn how to find index of a(n).
댓글 수: 0
채택된 답변
madhan ravi
2019년 5월 23일
편집: madhan ravi
2019년 5월 23일
Assuming you want to index of the last match in the matrix:
Index=find(a==3,1,'last')
댓글 수: 13
madhan ravi
2019년 5월 23일
편집: madhan ravi
2019년 5월 23일
No problem, by the way the original question you asked is totally irrelevant to your latter comment. Please don’t do this in the future riddling the answers.
Look into ind2sub() function to convert the linear indices. To understand what this statement means , you need to read the link which I shared thoroughly and practice. And finally have a look at ind2sub().
추가 답변 (1개)
KALYAN ACHARJYA
2019년 5월 23일
편집: KALYAN ACHARJYA
2019년 5월 23일
I want to know index of a(4) which is the bold 3
here ......................... this 4^ represent the index, I guessing you are looking for following one.
idx=find(a==3);
One dimentional case array case
>> a=[2,3,5,3,4,7,4,4,4];
>> idx=find(a==7)
idx =
6
>> idx=find(a==3)
idx =
2 4
But Matrices have 2 dimention so indices represents (x,y), where answer will be little different
>> a=magic(3)
a =
8 1 6
3 5 7
4 9 2
>> [r c]=find(a==3)
r =
2
c =
1
댓글 수: 5
참고 항목
카테고리
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!