continuous search of the closest rows in a matrix
古いコメントを表示
Hello,
Consider a 100x10 matrix and a random row of it, let be "row1".
I want to calculate the Euclidean distance between "row1" and the rest of the rows and I want to find the closest row to "row1", let be "row2".
Then I want to find the closest row to "row2", let be "row3" (the "row1" has been excluded from the matrix) and so on.
I use the "pdist2" for the Euclidean distance.
How you please help me?
Thank you.
Best,
Pavlos
4 件のコメント
Sean de Wolski
2013 年 1 月 15 日
So what have you tried so far? Why isn't pdist2() and a for-loop working?
pavlos
2013 年 1 月 15 日
José-Luis
2013 年 1 月 15 日
Please post what you have done so we can help you accordingly.
pavlos
2013 年 1 月 15 日
採用された回答
その他の回答 (1 件)
Teja Muppirala
2013 年 1 月 16 日
If you have the Statistics Toolbox installed, instead of using PDIST2, use PDIST (along with SQUAREFORM) instead. It is designed to find all interpoint distances for a single matrix very efficiently. Then your entire problem could be reduced to this:
M = randn(100,10);
L = size(R,1);
D = squareform(pdist(M));
D(1:L+1:L^2) = nan;
startrow = 1; % Starting Row
row = [startrow; zeros(L-1,1)];
for n = 2:L
oldrow = startrow;
[val,startrow] = min(D(:,startrow));
D(oldrow,:) = nan;
row(n) = startrow;
end
row
カテゴリ
ヘルプ センター および File Exchange で Nearest Neighbors についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!