How to detect equal rows of a matrix compare with another matrix with a 10 per cent of margin?

1 vue (au cours des 30 derniers jours)
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.

Réponse acceptée

ChristianW
ChristianW le 6 Fév 2013
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)

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by