compare 2 matrix with different dimensions

Hi, assume that I have a matrix 'info' (800,3), the first column is for ID, the second column is for coordinate x and the last column is for coordinate y. Additionally I have a matrix called 'coordinates'(200,2) where the first column is coordinate x and the second is coordinate y. I want to compare this matrix with the 'info' matrix to find the IDs where the matrix 'coordinates' is equal to the 'info' matrix.
Thanks

 채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 10일

1 개 추천

[tf, idx] = ismember( info(:,2:3), coordinates, 'rows');
match_IDs = info(tf, 1);

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 10일
편집: Azzi Abdelmalek 2013년 6월 10일

0 개 추천

A=[1 10 20;2 100 200;3 1000 2000;4 44 55]
B=[11 20;100 200;1 4;44 55 ]
out=A(~any(A(:,2:3)-B,2),1)

댓글 수: 5

Vanessa
Vanessa 2013년 6월 10일
Hi, when I use this I get an error
??? Error using ==> minus Matrix dimensions must agree.
I hope you can help me
Angus
Angus 2013년 6월 10일
I am wondering does this only output IDs that had matching 'x' values? I am asking as I am interested in how the 'any' function works. Does it only work down one vector?
Ok, it does not work, look at Walter's answer
Vanessa
Vanessa 2013년 6월 11일
sorry, my matrix was wrong, I fixed it and it works, thanks
any() by default works along the first dimension (so down columns), but it accepts an optional dimension number. dimension #2 means across rows.

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

카테고리

도움말 센터File 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