How to get first 3 maximum number in a matrix

2 ビュー (過去 30 日間)
Moe
Moe 2014 年 11 月 4 日
コメント済み: Adam 2014 年 11 月 5 日
Suppose I have a matrix m:
m = [7;1;4;4;12;2;6;10;2];
I want to find first 3 maximum in matrix m, means like:
n = [7;12;10]; % sorting is not issue

採用された回答

Adam
Adam 2014 年 11 月 4 日
temp = sort( m, 'descend' );
n = temp(1:3);
  2 件のコメント
Moe
Moe 2014 年 11 月 5 日
Thanks. How to find index number of n?
Adam
Adam 2014 年 11 月 5 日
[temp, idx] = sort( m, 'descend' );
n = temp(1:3);
idx = idx(1:3);

サインインしてコメントする。

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 4 日
n=sort(m)
n=n(end:end-2)

Matt J
Matt J 2014 年 11 月 5 日
Bruno Luong took the trouble to make a fast MEX implementation

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by