compare 2 matrix with different dimensions
6 次查看(过去 30 天)
显示 更早的评论
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
2013-6-10
[tf, idx] = ismember( info(:,2:3), coordinates, 'rows');
match_IDs = info(tf, 1);
0 个评论
更多回答(1 个)
Azzi Abdelmalek
2013-6-10
编辑:Azzi Abdelmalek
2013-6-10
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 个评论
Walter Roberson
2013-6-11
any() by default works along the first dimension (so down columns), but it accepts an optional dimension number. dimension #2 means across rows.
另请参阅
类别
在 Help Center 和 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!