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.

采纳的回答

ChristianW
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by