Filter löschen
Filter löschen

Sort a Matrix based on a column

2 Ansichten (letzte 30 Tage)
Kris zenitis
Kris zenitis am 9 Dez. 2011
Kommentiert: Azzi Abdelmalek am 19 Feb. 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???

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by