Effacer les filtres
Effacer les filtres

Sort a Matrix based on a column

2 vues (au cours des 30 derniers jours)
Kris zenitis
Kris zenitis le 9 Déc 2011
Commenté : Azzi Abdelmalek le 19 Fév 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???

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by