find the 3 maximum elements and their index

hi everyone, i have a vector and i need to find the 3 maximum elements and their index, plz can anyone help me in that? thx

 採用された回答

Srinivas
Srinivas 2012 年 2 月 29 日

1 投票

help sort

その他の回答 (1 件)

Jonathan Sullivan
Jonathan Sullivan 2012 年 2 月 29 日

3 投票

r = rand(100,1);
[val ind] = sort(r,'descend');
val(1:3)
ind(1:3)
r(ind(1:3))

2 件のコメント

amal
amal 2012 年 2 月 29 日
thank u very much i tried it and it worked, but i forgot to mention that i need to do it with simulink :s
Srinivas
Srinivas 2012 年 3 月 1 日
you can use the above written code in 'MATLAB Fucntion' block

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

カテゴリ

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

タグ

質問済み:

2012 年 2 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by