How do I sort the max values from a matrix ?

1 visualización (últimos 30 días)
Pierre Lonfat
Pierre Lonfat el 23 de Mayo de 2017
Editada: KSSV el 23 de Mayo de 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

Respuesta aceptada

Guillaume
Guillaume el 23 de Mayo de 2017
Editada: Guillaume el 23 de Mayo de 2017
[~, order] = sort(Occurences.Momentum(:, 2), 'descend');
top80 = Occurences.Momentum(order(1:80), :)
Or:
sortedData = sortrows(Occurences.Momentum, 2, 'descend');
top80 = sortedData(1:80, :)

Más respuestas (1)

KSSV
KSSV el 23 de Mayo de 2017
Editada: KSSV el 23 de Mayo de 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

Categorías

Más información sobre Shifting and Sorting Matrices 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