How do I sort the max values from a matrix ?
Show older comments
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
Accepted Answer
More Answers (1)
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
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!