Compare two matrices and find similar values
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Shashank
el 12 de Feb. de 2018
What do you mean by closest values?
Please give the example of how the output should be for the above 2 matrices
Respuestas (1)
lokender Rawat
el 13 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!