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에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by