matlab中排序(矩阵的行排序及列排序)

>> a=[1,2,3;4,6,0;0,5,2]

a =

     1     2     3
     4     6     0
     0     5     2

>> sort(a)

ans =

     0     2     0
     1     5     2
     4     6     3

>> sort(a,'descend')

ans =

     4     6     3
     1     5     2
     0     2     0

即matlab中对矩阵默认按列升序排序;如果降序排序使用sort(a,'descend'),升序使用sort(a,'ascend'),

1 >> sort(a,'ascend')
2 
3 ans =
4 
5      0     2     0
6      1     5     2
7      4     6     3

 对某列进行排序:

1 >> sort(a(:,2),'descend')
2 
3 ans =
4 
5      6
6      5
7      2

 对某行进行排序:

1 >> sort(a(2,:),'descend')
2 
3 ans =
4 
5      6     4     0
原文地址:https://www.cnblogs.com/yuzhuwei/p/4092838.html