How to get first 3 maximum number in a matrix

3 visualizaciones (últimos 30 días)
Moe
Moe el 4 de Nov. de 2014
Comentada: Adam el 5 de Nov. de 2014
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Nov. de 2014
n=sort(m)
n=n(end:end-2)

Matt J
Matt J el 5 de Nov. de 2014
Bruno Luong took the trouble to make a fast MEX implementation

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by