按降序对MATLAB数组进行排序 [英] Sort MATLAB array in descending order

查看:617
本文介绍了按降序对MATLAB数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MATLAB.我有一个问题,关于如何沿矩阵的一列按降序对矩阵进行排序,而其余的行值也照此进行.

I am using MATLAB. I have a question about how to sort an matrix in descending order along one column of a matrix and have the rest of the row values follow suit.

例如,

A = [1 30; 2 40; 3 10; 4 50; 5 20]

成为

B = [4 50; 2 40; 1 30; 5 20; 3 10]

谢谢

推荐答案

使用SORTROWS函数,指定您要使用 second 列以降序顺序进行排序. ..

Use the SORTROWS function, specifying that you want to sort using the second column in descending order...

B = sortrows(A, -2);

在这里,2表示在第2列中排序",而2前面的负号表示按 de 升序".有关更多信息,请参见 MATLAB文档.

Here, the 2 means "sort in column 2," and the negative sign in front of the 2 means "in de-scending order." See the MATLAB documentation for more information.

这篇关于按降序对MATLAB数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆