フィルターのクリア

Sort Data by Second Column

38 ビュー (過去 30 日間)
Brian Robinson
Brian Robinson 2020 年 5 月 26 日
回答済み: Brian Robinson 2020 年 5 月 26 日
Hello there,
I have data witht the first column being the year and the second column being the rainfall. I would like to sort the data from largest rainfall to smallest while keeping the associated years the same. I have tried using the Sort function of exactly how to do this.
Any help is appreciated,
Thanks,
Brian

採用された回答

Stephen23
Stephen23 2020 年 5 月 26 日
編集済み: Stephen23 2020 年 5 月 26 日
Use sortrows, e.g. where M is your matrix:
M = sortrows(M,2);
If you really want to use sort, then of course you will need to use indexing, e.g.:
[~,idx] = sort(M(:,2));
M = M(idx,:);

その他の回答 (1 件)

Brian Robinson
Brian Robinson 2020 年 5 月 26 日
Thanks Stephen.

カテゴリ

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