How do I sort the max values from a matrix ?

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

 採用された回答

Guillaume
Guillaume 2017 年 5 月 23 日
編集済み: Guillaume 2017 年 5 月 23 日

1 投票

[~, order] = sort(Occurences.Momentum(:, 2), 'descend');
top80 = Occurences.Momentum(order(1:80), :)
Or:
sortedData = sortrows(Occurences.Momentum, 2, 'descend');
top80 = sortedData(1:80, :)

その他の回答 (1 件)

KSSV
KSSV 2017 年 5 月 23 日
編集済み: KSSV 2017 年 5 月 23 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

質問済み:

2017 年 5 月 23 日

編集済み:

2017 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by