How to find similar rows in two matrices?
1 次查看(过去 30 天)
显示 更早的评论
I have two long matrices with 3 rows, namly the radii, the x- and the y-coordinates of a circle. Now I would like to compare the two matrices in order to find out which ones belong to each other (meaning: which ones have the similar values). Unfortunatly, the matrices do NOT have the same amount of rows (one has 70, the other one has 74). dimension does not fit...
How would you do it? It tried to add rows containing zeros and substrate the matrices. thats not a elegant way to do it, though.
My goal is a third matrix containing only the similar circles....
0 个评论
回答(1 个)
Sean de Wolski
2012-11-6
编辑:Sean de Wolski
2012-11-7
You could try ismember with the 'rows' option. But this will require them to be equal not similar. Alternatively, you could write something that implements an are rows close type of thing. We could help you with that if you could provide a dataset for us to work with.
More
Here is how I would approach this. Basically we want to take the sqrt sum of squared differences between each row combination. I would do this using the following:
MyDists = reshape(sqrt(sum(bsxfun(@minus,mB1,reshape(mB2.',1,3,[])).^2,2)),size(mB1,1),size(mB2,1));
Now MyDists will contain the distance between each rows in a matrix format.
If you put a threshold on this you can then determine which rows/columns are within a certain distance of each other.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!