根据Matlab中的一列对整个矩阵进行排序 [英] Sorting entire matrix according to one column in matlab

查看:97
本文介绍了根据Matlab中的一列对整个矩阵进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的矩阵如下

a =

 1     3
 2     5
 3     2
 4     8
 5     9

我想对a矩阵中的第二列进行排序.我希望第一列的相应行按如下方式打印:

I want to sort the second column in the a matrix. I want the corresponding rows of column one to be printed as follows :

a =

 3     2
 1     3
 2     5
 4     8
 5     9

我尝试了sort(a),但是它仅对矩阵a的第二列进行排序.

I tried sort(a), but it is sorting only the second column of matrix a.

推荐答案

尝试一下:

sortrows(a,2)

这应该根据第二列进行排序.

This should sort according to the second column.

这篇关于根据Matlab中的一列对整个矩阵进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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