フィルターのクリア

sort the rows of a matrix based on their distance from the mean

3 ビュー (過去 30 日間)
pavlos
pavlos 2012 年 3 月 1 日
回答済み: Rod 2016 年 3 月 17 日
Hello,
Consider a 20x10 matrix.
I am interested in sorting its rows based on their euclidean distance from the mean (average).
The closest row to the mean will have the shortest distance from it.
Any help please?
Thank you.
Best,
Pavlos

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 3 月 1 日
  1. calculate the distances as Walter did in your other thread
  2. sort this and keep the second output (ind) [~, ind] = sort(...)
  3. reorder your matrix rowwise by ind Msorted = M(ind,:)
  1 件のコメント
pavlos
pavlos 2012 年 3 月 1 日
Thank you very much.
Best,
Pavlos

サインインしてコメントする。

その他の回答 (1 件)

Rod
Rod 2016 年 3 月 17 日
Heres a full bit of code to do this Hope this will help someone out.
scaleX = X - repmat(mean(X),length(X),1);
XD = sqrt(sum(abs(scaleX).^2,2));
[~,idxs] = sort(XD);
XRSorted = X(idxs,:);
Note: This assumes X is a matrix with each column as a different dimension.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by