I think you want either the mode
or the histc
function.
M=mode(X) for vector X computes M as the sample mode, or most frequently occurring value in X.
Example with your data:
x = [56 56 64 64 64 70 87 65];
mode(x)
ans =
64
But this will only get you the most frequently occurring value.
If you want the count of each unique item in the array, you could do,
unqx = unique(x);
unqx =
56 64 65 70 87
valueCount = histc(x, unqx)
ans =
2 3 1 1 1
You could then sort this and take the first N
values
valueCount = sort(valueCount, 'descend');
% Use unqx(valueCount(1:N))