Effacer les filtres
Effacer les filtres

Compare two matrices and find similar values

1 vue (au cours des 30 derniers jours)
Michela Longhi
Michela Longhi le 8 Fév 2018
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
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
Michela Longhi
Michela Longhi le 12 Fév 2018
such as: if
6 40 279 (from matrix 2)
is closet to
6 40 110 (from matrix 1)
or to
6 40 573 (from matrix 1)
and the answer is, obviously, 6 40 110

Connectez-vous pour commenter.

Réponses (1)

lokender Rawat
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].

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!

Translated by