x=[1 2 3 4 5 6 ;
6 4 3 2 2 1 ;
1 6 6 4 6 6 ;
3 4 5 6 6 6;
1 4 6 6 2 3;
1 3 6 4 6 6];
[m,n]=size(x);
x1=reshape(x,1,m*n);
k = max(x1)-min(x1)+1;
hist(x1,k);
x2 = min(x1):max(x1);
m = histc(x1,min(x1):max(x1));
result = [x2;m]
>>
result =
1 2 3 4 5 6
5 4 5 6 2 14