Help Sorting columns

3 ビュー (過去 30 日間)
André Pacheco
André Pacheco 2012 年 5 月 18 日
Hello there,
I'm having a few troubles in my matlab program. the problem his: Having a matrix like this: [2 2 0 4; 5 4 2 5; 8 6 1 4; 1 2 4 2; 56 50 30 49] i would like to be able to sort it ascending by the last line (56 , 50, 30 49). It would generate an output similar to this: [0 4 2 2; 2 5 4 5 ; 1 4 6 8 ; 4 2 2 1; 30 49 50 56]
All columns must move with the last one. Thanks in advance,
Andre

採用された回答

Geoff
Geoff 2012 年 5 月 18 日
Get the indices for sorting the last row:
[~, I] = sort( data(end,:) );
And then reindex your matrix:
sdata = data(:, I);
  1 件のコメント
André Pacheco
André Pacheco 2012 年 5 月 18 日
Thank you very much! You saved me! :D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by