How to get first 3 maximum number in a matrix

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

 Akzeptierte Antwort

Adam
Adam am 4 Nov. 2014

1 Stimme

temp = sort( m, 'descend' );
n = temp(1:3);

2 Kommentare

Moe
Moe am 5 Nov. 2014
Thanks. How to find index number of n?
[temp, idx] = sort( m, 'descend' );
n = temp(1:3);
idx = idx(1:3);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Gefragt:

Moe
am 4 Nov. 2014

Kommentiert:

am 5 Nov. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by