Compare values within a matrix
이전 댓글 표시
I am comparing two matrices of different dimensions (A and B). I want to find values in B that are within 1 number unit to A. Is there anyway I can do this? B is a smaller matrix than A.
Thanks
댓글 수: 1
Azzi Abdelmalek
2015년 6월 23일
What does that mean?
답변 (2개)
Ingrid
2015년 6월 23일
if you mean to find all numbers that are equal to each other when disregarding the numbers behind the comma than you can use something like this
A_r = round(A);
B_r = round(B);
C = intersect(A_r,B_r);
댓글 수: 1
Yewande Oni
2015년 6월 23일
편집: Yewande Oni
2015년 6월 23일
Jan
2015년 6월 23일
A = [31 16 8; 38 4 10];
B = [30 15 7; 34 5 14];
nA = size(A, 1);
match = false(1, nA)
for iA = 1:nA
D = abs(bsxfun(@minus, A(iA, :), B)) <= 1.0;
match(iA) = any(all(D, 2));
end
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!