How to detect equal rows of a matrix compare with another matrix with a 10 per cent of margin?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a matrix and I want to compare rows of this matrix to rows of another matrix and verify if there are rows wich match them.
For example:
A = 1 2 3; 4 5 6; 7 8 9
B = 54 23 13; 54 32 12; 1.1 2.2 2.9
I need to detect that row 1 of the Matrix A match with the row 3 of the Matrix B. The rows are not equal because I want a +-10 per cent of margin.
Thank you very much.
0 件のコメント
採用された回答
ChristianW
2013 年 2 月 6 日
m = 0.1; % margin
A = [1 2 3; 4 5 6; 7 8 9];
B = [7 8 10; 4 5 12; 1.1 2.2 2.9; 1.101 2 3; 6.3 7.2 9.9];
k = 0;
for i = 1:size(A,1)
for j = 1:size(B,1)
if all(abs((A(i,:)-B(j,:))./A(i,:)) <= m+eps)
k = k+1;
match(:,k) = [i;j]; %#ok<SAGROW>
end
end
end
fprintf('A row %d matches B row %d.\n',match)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!