>> 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

 

版权声明:本文为yuzhuwei原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/yuzhuwei/p/4092838.html