How to find similar rows in two matrices?
Show older comments
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....
Answers (1)
Sean de Wolski
on 6 Nov 2012
Edited: Sean de Wolski
on 7 Nov 2012
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.
4 Comments
Alexander Esser
on 6 Nov 2012
Alexander Esser
on 6 Nov 2012
Edited: Alexander Esser
on 6 Nov 2012
Alexander Esser
on 7 Nov 2012
Sean de Wolski
on 7 Nov 2012
See More
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!