finding the closest values in a set of data
조회 수: 1 (최근 30일)
이전 댓글 표시
basically i have 2 sets of data:
A = [4; 7; 13; 44; 55;];
B = 1; 3; 8; 9; 33; 45; 48; 53; 54; 66];
I want to compare every value in A to every value in B, and then have MATLAB figure out where the closest values of all those in A occur in B. So 4 is closest to 3, 7 is closest to 8, 13 is closest to 9, etc.
I want my output to be an index list in terms of B.. so basically i need:
index = [2; 3; 4; 6; 9]
Is this possible?
댓글 수: 0
채택된 답변
Sean de Wolski
2011년 6월 9일
[junk,index] = min(bsxfun(@(x,y)abs(x-y),A,B'),[],2);
Of course it's possible!
댓글 수: 0
추가 답변 (1개)
Fangjun Jiang
2011년 6월 9일
A = [4; 7; 13; 44; 55;];
B = [1; 3; 8; 9; 33; 45; 48; 53; 54; 66];
C=bsxfun(@minus,A,B');
[D,Index]=min(abs(C),[],2)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!