Effacer les filtres
Effacer les filtres

find index of last 5 largest values in cell array

3 vues (au cours des 30 derniers jours)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan le 24 Août 2015
Commenté : Star Strider le 24 Août 2015
I have a cell array of numbers a = {5 ; 6 ; 8 ; 8 ; 10; 1 ; 15 ; 25 ; 10 ; 35 ; 45 ; 3}
I need to find the index of last five largest values in cell array
index = 11,10,8,7,5
How can i do this ?
Thanks a lot

Réponse acceptée

Star Strider
Star Strider le 24 Août 2015
This works:
[as,idx] = sort(cell2mat(a),'descend');
result = idx(1:5);
  2 commentaires
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan le 24 Août 2015
Modifié(e) : Gopalakrishnan venkatesan le 24 Août 2015
Thank you. How to avoid the repetition index , for example if my cell array consists of
a = {10,10,5,10,3,6,6,3,6,9,8}
index = 1, 10, 11 , 6, 3
Star Strider
Star Strider le 24 Août 2015
My pleasure.
The unique function works for the second problem:
[C,idx] = unique(cell2mat(a));
result = idx(end-4:end);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by