How to get first 3 maximum number in a matrix

3 次查看(过去 30 天)
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 个)

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 CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by