How to find the K max or min values contained in a vector?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Before I attempt to write the code myself, I was wondering if a function already exists to find the k max values of a vector.
E.g. test_vec = [ 5 9 8 3 2 1 7 6]; k = 3; [max_vals, max_ids] = max_elems(test_vec, k); max_vals = [ 9 8 7] max_ids = [2 3 7]
0 Commenti
Risposte (1)
Sean de Wolski
il 13 Feb 2012
sort it 'descend' and extract the first k values.
2 Commenti
Walter Roberson
il 13 Feb 2012
[max_vals, max_ids] = sort(test_vec, 'descend');
max_vals = max_vals(1:k);
max_ids = max_ids(1:k);
Vedere anche
Categorie
Scopri di più su Graphics Object Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!