【问题标题】:sort data from large to small数据从大到小排序
【发布时间】:2014-02-14 12:23:33
【问题描述】:

在数据集中,如何对数据进行从大到小的排序? 使用sort数据由小变大:

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

但我想要b

b=[6 5 3 2 1]

【问题讨论】:

标签: matlab sorting


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    Yuan's answer 是要走的路。

    一些更骇人听闻的替代方案:

    b = -sort(-a);
    b = fliplr(sort(a));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多