find the 3 maximum elements and their index

3 visualizaciones (últimos 30 días)
amal
amal el 29 de Feb. de 2012
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

Respuesta aceptada

Srinivas
Srinivas el 29 de Feb. de 2012
help sort

Más respuestas (1)

Jonathan Sullivan
Jonathan Sullivan el 29 de Feb. de 2012
r = rand(100,1);
[val ind] = sort(r,'descend');
val(1:3)
ind(1:3)
r(ind(1:3))
  2 comentarios
amal
amal el 29 de Feb. de 2012
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 el 1 de Mzo. de 2012
you can use the above written code in 'MATLAB Fucntion' block

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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