Sorting elements in a matrix via first column characterization
4 ビュー (過去 30 日間)
古いコメントを表示
I'd like to know if there's a way to sort rows of a matrix by the entries in the first column.
For example, if I have a matrix
A = [9 4 5; 3 3 1; 5 8 4;]
I want to do something like "B = sort(A)" and have MATLAB return:
B = [3 3 1; 5 8 4; 9 4 5;]
Where all rows are sorted based on the first entry. Thanks.
回答 (1 件)
Andrei Bobrov
2015 年 6 月 15 日
編集済み: Andrei Bobrov
2015 年 6 月 15 日
B = sortrows(A,1);
or
[~,ii] = sort(A(:,1));
B = A(ii,:);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!