How to detect equal rows of a matrix compare with another matrix with a 10 per cent of margin?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
ChristianW
el 6 de Feb. de 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)
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!