How to find the most similar row in matrix A to matrix B
1 次查看(过去 30 天)
显示 更早的评论
I have Two matrix A &B as follows"
A=[1.2 2.0 3.3;1.2 2.0 3.2;1.1 2.1 3.3]
B=[1.1 2.0 3.2]
I want to find most similar row in matrix A(&elements) to matrix B. Please kindly help some how can I trace the most similar one.
Many Thanks in advance.
2 个评论
Steven Lord
2015-7-1
A = [1 1 1];
B = [1 1 1e6];
C = [10 10 10];
Which of B or C is "most similar" to A? B matches two of the three elements exactly, but the third is rather far off. C doesn't match ANY of the elements in A exactly, but it's not as far off as B's third element.
采纳的回答
Andrei Bobrov
2015-7-1
variant
A=[1.2 2.0 3.3;1.2 2.0 3.2;1.1 2.1 3.3];
B=[1.1 2.0 3.2];
a = sqrt(sum(bsxfun(@minus,A,B).^2));
[~,t] = min(a);
out = A(t,:);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!