How do I get the position of the highest numbers of a vector?

1 visualización (últimos 30 días)
gsourop
gsourop el 9 de Abr. de 2017
Comentada: gsourop el 9 de Abr. de 2017
Hi everyone,
Does anyone know how to get the position of 4 highest numbers of a vector? For example,
rng(1)
a = randn(10,1)
a =
-0.6490
1.1812
-0.7585
-1.1096
-0.8456
-0.5727
-0.5587
0.1784
-0.1969
0.5864
Clearly the four highest numbers are 1.1812 , 0.5864 , 0.1784 and -0.1969. That correspond to element 2,10,8 and 9, respectively. How can I get this sequence in a vector form, ie 4x1?
Thanks a lot.

Respuesta aceptada

dpb
dpb el 9 de Abr. de 2017
>> [mx,ix]=sort(a,'descend');
>> N=4;
>> num2str([ix(1:N) mx(1:N) ],'Posn %2d Value %7.4f')
ans =
Posn 2 Value 1.1812
Posn 10 Value 0.5864
Posn 8 Value 0.1784
Posn 9 Value -0.1969
>>

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by