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!