且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Matlab在2个矩阵中找到最相似的行

更新时间:2023-02-17 17:32:35

解决方案

感谢提供的评论,我设法提出了一个不优雅"但可行的解决方案.

Thanks to the comments provided I managed to come up with a "not elegant" but working solution.

B_rem = B;
weights_error = [2 4 1];
match = zeros(size(A,1),2);

for i = 1 : size(A,1)
    score = zeros(size(B_rem,1),1);
    for j =1 : size(B_rem,1)
        score(j) = sum(abs(A(i,:) - B_rem(j,:)).*weights_error);
    end
    [~,idxmin] = min(score);
    match(i,:) = [i,idxmin];
    B_rem(idxmin,:)=[1000 1000 1000];

end

indx = match;

table_match = zeros(size(A,1),7);
table_match(:,1:3) = A(match(:,1),:);
table_match(:,5:7) = B(match(:,2),:);