First 5 minimum elements of a vector

I found the minimum element of vector by
[m index]=min(vector);
How to find first five minimum elements of a vector and its index??

2 comentarios

Jan
Jan el 7 de Feb. de 2013
There is no minimum command in Matlab.
Bless
Bless el 7 de Feb. de 2013
thanks, I wrongly typed for min...

Iniciar sesión para comentar.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Feb. de 2013
Editada: Azzi Abdelmalek el 7 de Feb. de 2013
vector=rand(10,1)
[x,idx]=sort(vector)
out_x=x(1:5) % 5 first values
out_idx=idx(1:5) % corresponding indices

1 comentario

Amir Hosein Fardi
Amir Hosein Fardi el 23 de Nov. de 2021
that was really helpful
after 5 yrs of matlab programming today I was thinking about it and I really got confused to find the proper way to do that .

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 7 de Feb. de 2013

Comentada:

el 23 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by