我将如何在 MATLAB 中进行嵌套排序? [英] How would I do a nested sort in MATLAB?

查看:21
本文介绍了我将如何在 MATLAB 中进行嵌套排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 MATLAB 中使用矩阵进行嵌套排序.假设我的矩阵如下所示:

I am looking to do a nested sort with a matrix in MATLAB. Say my matrix looks like this:

[b a; 
 b c;
 a c;
 a a]

我想先按第一列排序并保持该排序,然后按第二列排序.结果将是:

I would like to first sort by the first column and maintain that sort, then sort by the second column. The result would be:

[a a;
 a c;
 b a;
 b c]

怎么做?

推荐答案

sortrows 可以解决问题.

更详细地说,sortrows(A,[1 2]),其中 A 是您的矩阵.

To be more detailed, sortrows(A,[1 2]), where A is your matrix.

这篇关于我将如何在 MATLAB 中进行嵌套排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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