position of values in a matrix

조회 수: 5 (최근 30일)
sampath kumar punna
sampath kumar punna 2019년 10월 29일
댓글: sampath kumar punna 2019년 10월 30일
i have a set of matrix
23 24
35 2
12 19
24 23
12 15
26 17
i want to know the position of in the matrix of [35 2], [12 15]
which is 2 and 5
is it possible to get the position of it.

답변 (2개)

Alex Mcaulley
Alex Mcaulley 2019년 10월 29일
A = [23 24
35 2
12 19
24 23
12 15
26 17]
loc = find(ismember(A,[35 2],'rows'))
loc =
2
  댓글 수: 1
Alex Mcaulley
Alex Mcaulley 2019년 10월 29일
Another option:
[~,loc,~] = intersect(A,[35 2],'rows')
loc =
2

댓글을 달려면 로그인하십시오.


ME
ME 2019년 10월 29일
If I understand what you are asking then you could use:
Z=[23 24; 35 2; 12 19; 24 23; 12 15; 26 17];
M=[35 2; 12 15];
pos = find(ismember(Z, M, 'rows') == 1);
where Z is your original matrix, M is a matrix of the items you want to search for and pos is the output containing the locations of those items.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 10월 29일
good sportiveness
sampath kumar punna
sampath kumar punna 2019년 10월 30일
this code is not working when the elements in the row are repeated

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by