If i have a matrix A with n values spanning from 65:90. How do i get the 10 most common values in A? I want the result to be a 10x2 matrix B with the 10 common values in the first column and the times it appears in the second column.
A = [65 82 65 90; 90 70 72 82]; % Your data
range = 65:90;
res = [range; histc(A(:)', range)]'; % res has values in first column, counts in second.
Now all you’ve got to do is sort the res
array by the second column and take the first 10 rows.
sortedres = sortrows(res, -2); % sort by second column, descending
first10 = sortedres(1:10, :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With