Compare two matrices and find similar values
2 views (last 30 days)
Show older comments
I have two matrices with 3 column each. I want to compare the rows, the first matrix is:
6 40 110
6 40 573
6 41 66
6 41 471
6 41 691
6 41 945
6 42 201
6 42 468...
and the second is:
6 40 79
6 40 179
6 40 279
6 40 379
6 40 479
6 40 579...
I want to compare the rows of these two matrices and find the closest values each other. Any suggestion?
2 Comments
Shashank
on 12 Feb 2018
What do you mean by closest values?
Please give the example of how the output should be for the above 2 matrices
Answers (1)
lokender Rawat
on 13 Feb 2018
From my understanding,you want to find the closest matching row in matrix B for each of the rows in matrix A in terms of its values. Suppose, for the first row of matrix A [6 40 110] , the closest matching row in matrix B should be [6 40 79]. You can use the following:
[~,indx]=min(pdist2(B,A(i,:),'euclidean'));
result=B(indx,:);
result
where i= rowNumber of matrix A you want to find the match for. Similarly, for row 2 of matrix A [6 40 573], the closest matching row in matrix B should be [6 40 579].
0 Comments
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!