MATLAB: First 5 minimum elements of a vector

minimum

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??

Best Answer

vector=rand(10,1)
[x,idx]=sort(vector)
out_x=x(1:5) % 5 first values
out_idx=idx(1:5) % corresponding indices