How do I sort the max values from a matrix ?

2 vues (au cours des 30 derniers jours)
Pierre Lonfat
Pierre Lonfat le 23 Mai 2017
Modifié(e) : KSSV le 23 Mai 2017
Hello everyone !
In the following 577X2 matrix I have tickers of stocks in the first column and the number of occurence in the second one.
How would I keep the 80 first stocks (tickers) that occurred the most ?
Many thanks in advance !
Pierre

Réponse acceptée

Guillaume
Guillaume le 23 Mai 2017
Modifié(e) : Guillaume le 23 Mai 2017
[~, order] = sort(Occurences.Momentum(:, 2), 'descend');
top80 = Occurences.Momentum(order(1:80), :)
Or:
sortedData = sortrows(Occurences.Momentum, 2, 'descend');
top80 = sortedData(1:80, :)

Plus de réponses (1)

KSSV
KSSV le 23 Mai 2017
Modifié(e) : KSSV le 23 Mai 2017
Let data be you 577X2 data.
[val,idx] = sort(data(:,2),'descend') ; % sort the second column in descending order
iwant = data(idx(1:80),:) ; % pick first 80 most occurring stocks

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by