フィルターのクリア

How can I sort the rows of a matrix in descending order in MATLAB 7.0.1 (R14SP1)?

9 ビュー (過去 30 日間)
I have a matrix A defined as follows:
A = [7 1;2 4;5 1;3 2];
I would like to sort the rows of A in descending order along the first column.

採用された回答

MathWorks Support Team
MathWorks Support Team 2010 年 1 月 21 日
The SORTROWS function offers the ability to sort the rows of a matrix in descending order by specifying a negative value for the appropriate column in the second argument to the function.
For example, the following call to SORTROWS will sort the rows of matrix A by descending order of column 2 and then by ascending order of column 1:
B = sortrows(A,[-2 1])
B =
2 4
3 2
5 1
7 1
This feature is documented in the function reference for SORTROWS in the documentation in MATLAB versions 7.1 (R14SP3) and higher. For previous versions you may consult the file help content which contains this information by executing the following at the MATLAB prompt:
help sortrows

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by