How would I do a nested sort in MATLAB?

2019-01-28 05:38发布

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]

How would it be done?

1条回答
2楼-- · 2019-01-28 05:44

sortrows would do the trick.

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

查看更多
登录 后发表回答