将数据从大到小排序

时间:2014-02-14 12:23:33

标签: matlab sorting

在数据集中,如何将数据从大到小排序? 使用sort数据从小到大:

a=[1 3 5 2 6];
b=sort(a);
b=[1 2 3 5 6];

但我想要b

b=[6 5 3 2 1]

2 个答案:

答案 0 :(得分:6)

检查http://www.mathworks.com/help/matlab/ref/sort.html。 sort函数可以采用mode参数。

b = sort(a) % 'ascend' by default

b = sort(a, 'descend') % sort data from large to small

答案 1 :(得分:4)

Yuan's answer是要走的路。

一些稍微更为苛刻的替代品:

b = -sort(-a);
b = fliplr(sort(a));
相关问题