Compare two matrices and find similar values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Shashank
le 12 Fév 2018
What do you mean by closest values?
Please give the example of how the output should be for the above 2 matrices
Réponses (1)
lokender Rawat
le 13 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!