詳解Matlab中 sort 函數用法,matlabsort

來源:互聯網
上載者:User

詳解Matlab中 sort 函數用法,matlabsort

(1)B=sort(A) 對一維或二維數組進行升序排序,並返回排序後的數組,當A為二維時,對數組每一列進行排序.

eg: A=[1,5,3],則sort(A)=[1,3,5]

A=[1,5,3;2,4,1],則sort(A)=[1,4,1;2,5,3]

(2)B=sort(A,dim),對數組按指定方向進行升序排序,

dim =1,表示對每一列進行排序,,dim=2表示對每一行進行排序.

(3)B=sort(A,dim,mode),mode為指定排序模式,mode為"ascend"時,進行升序排序,為"descend "時,進行降序排序.

(4)[B,I]=sort(A,.....),I為返回的排序後元素在原數組中的行位置或列位置.

一些例子:

>> A=[3 4 2;1 5 3;4 7 1]

A =

3 4 2
1 5 3
4 7 1

>> A(:)

ans =

3
1
4
4
5
7
2
3
1

>> min(A(:))

ans =

1

>> max(A(:))

ans =

7

>> A

A =

3 4 2
1 5 3
4 7 1

>> sort(A)

ans =

1 4 1
3 5 2
4 7 3

>> A

A =

3 4 2
1 5 3
4 7 1

>> sort(A(:))

ans =

1
1
2
3
3
4
4
5
7

>> sort(A,1)

ans =

1 4 1
3 5 2
4 7 3

>> sort(A,2)

ans =

2 3 4
1 3 5
1 4 7

>> sort(A,1,"descend")
??? sort(A,1,"descend")

Error: Missing variable or function.

>> sort(A,1,'descend')

ans =

4 7 3
3 5 2
1 4 1

>> [B,I]=sort(A)

B =

1 4 1
3 5 2
4 7 3

I =

2 1 3
1 2 1
3 3 2

以上內容簡單給大家介紹了matlab中 sort 函數用法 ,希望對大家以上協助,更多有關sort函數的相關知識請登入幫客之家網站官網瞭解更多!

您可能感興趣的文章:
  • Lua的table庫函數insert、remove、concat、sort詳細介紹
  • php數組排序usort、uksort與sort函數用法
  • C語言中qsort函數用法執行個體小結
  • 淺析C/C++中sort函數的用法
  • PHP中的排序函數sort、asort、rsort、krsort、ksort區別分析
  • Perl Sort函數用法總結和使用執行個體
  • C++標準模板庫函數sort的那些事兒
  • PHP array_multisort() 函數的深入解析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.