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 日

0 投票

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 日

0 投票

Thanks Stephen.

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

質問済み:

2020 年 5 月 26 日

回答済み:

2020 年 5 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by