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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM