필터 지우기
필터 지우기

Comparing matrices with different dimensions

조회 수: 2 (최근 30일)
Mahi Nazir
Mahi Nazir 2013년 9월 27일
답변: dpb 2013년 9월 27일
I have a matrix [row, col, vector] with a large number of entries for row, col and vector.
I have another matrix [x, y] with few entries.
I want to derive a matrix [xr, yc, zv] for all the values for which (x==row and y==col) and zv should be the corresponding value of 'vector' for which (x=row and y=col)
e.g:
[row col vector]= 2 2 4;
3 2 6;
7 1 8;
5 2 3;
8 1 7;
[x y]= 3 2;
8 1
then, [xr yc zv] should equal = 3 2 6;
8 1 7
Your help will be greatly appreciated. Thanks!

채택된 답변

Image Analyst
Image Analyst 2013년 9월 27일
Use ismember() with the rows option:
m= [2 2 4;
3 2 6;
7 1 8;
5 2 3;
8 1 7]
m2= [3 2;
8 1
7 3]
matches = ismember(m(:,1:2), m2, 'rows')
out = m(matches,:)
  댓글 수: 1
Mahi Nazir
Mahi Nazir 2013년 9월 27일
Brilliant! Thank you very much for a quick and appropriate response

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

추가 답변 (1개)

dpb
dpb 2013년 9월 27일
Since your values are in the first two columns, it's fairly easily written...
>> res=a(ismember(a(:,1:2),v,'rows'),:)
res =
3 2 6
8 1 7
>>

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by