- calculate the distances as Walter did in your other thread
- sort this and keep the second output (ind) [~, ind] = sort(...)
- reorder your matrix rowwise by ind Msorted = M(ind,:)
sort the rows of a matrix based on their distance from the mean
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
pavlos
el 1 de Mzo. de 2012
Respondida: Rod
el 17 de Mzo. de 2016
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
0 comentarios
Respuesta aceptada
Sean de Wolski
el 1 de Mzo. de 2012
Más respuestas (1)
Rod
el 17 de Mzo. de 2016
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.
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!