MATLAB: Sort the rows of a matrix based on their distance from the mean

matrix manipulationsort

Hello,
Consider a 20×10 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

Best Answer

  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,:)