Sort a Matrix based on a column

1 visualización (últimos 30 días)
Kris zenitis
Kris zenitis el 9 de Dic. de 2011
Comentada: Azzi Abdelmalek el 19 de Feb. de 2014
I want to sort a matrix. Actually I want to sort the last column and all the rest columns based on the last. Has anyone idea about this???

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Dic. de 2011
[lastvals, idx] = sort(A(:,end));
sortedA = A(idx,:);
  2 comentarios
Walter Roberson
Walter Roberson el 9 de Dic. de 2011
Sorry I had the index order reversed. It is fixed in my Answer now.
Azzi Abdelmalek
Azzi Abdelmalek el 19 de Feb. de 2014
[Kris zenitis commented]
I ve got a matrix 4000x9. When i tried your solution i got Index exceeds matrix dimensions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by