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 件のコメント

Jan
Jan 2013 年 2 月 7 日
There is no minimum command in Matlab.
Bless
Bless 2013 年 2 月 7 日
thanks, I wrongly typed for min...

サインインしてコメントする。

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 7 日
編集済み: Azzi Abdelmalek 2013 年 2 月 7 日

1 投票

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

1 件のコメント

Amir Hosein Fardi
Amir Hosein Fardi 2021 年 11 月 23 日
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 .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by