Sorting a Matrix by columns

17 ビュー (過去 30 日間)
NotRiyad NotHosein
NotRiyad NotHosein 2021 年 3 月 20 日
コメント済み: NotRiyad NotHosein 2021 年 3 月 21 日
I have a 12 x 12 matrix and I have used the command 'sortrows' to sort the matrix in ascending order of rows. How can I do the same but sorting by columns (i.e. ascending order of columns) instead of rows?

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 3 月 21 日
I would suggest transposing your matrix, sortrows, then transpose the result.
A=rand(5)
A = 5×5
0.2220 0.3790 0.0549 0.6643 0.6145 0.0431 0.4532 0.5809 0.2667 0.4518 0.7695 0.6946 0.0495 0.6197 0.7591 0.7629 0.7669 0.7549 0.9592 0.4810 0.3152 0.3356 0.0617 0.1093 0.6415
B=sortrows(A')'
B = 5×5
0.0549 0.2220 0.3790 0.6145 0.6643 0.5809 0.0431 0.4532 0.4518 0.2667 0.0495 0.7695 0.6946 0.7591 0.6197 0.7549 0.7629 0.7669 0.4810 0.9592 0.0617 0.3152 0.3356 0.6415 0.1093
  1 件のコメント
NotRiyad NotHosein
NotRiyad NotHosein 2021 年 3 月 21 日
Thank you very much! I used sortrow on the transposed matrix and figured it just didnt work. Didn't think to transpose that as well, makes sense.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by