Filter löschen
Filter löschen

Sort a matrix based on one row?

77 Ansichten (letzte 30 Tage)
Umesh
Umesh am 22 Apr. 2013
lets say we have a 3x3 matrix as
a= 2 5 3;
2 8 1;
4 1 9;
and I want this matrix sorted based on its 2nd row in ascending order i.e.
answer= 3 2 5;
1 2 8;
9 4 1;
Thank you for any help you can offer.

Antworten (1)

Walter Roberson
Walter Roberson am 22 Apr. 2013
[temp, order] = sort(a(2,:));
answer = a(:,order);

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by