Compare two matrices and find similar values

2 次查看(过去 30 天)
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 个评论
Shashank
Shashank 2018-2-12
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 2018-2-12
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

请先登录,再进行评论。

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by