MATLAB: How to count the occurrences of a value for an matrix

digital image processinghistogrammatrix manipulation

a= [ 3 4 5; 7 8 9; 3 6 8 ; 4 6 9; 3 6 5]
I expected the ans:
b=
[ 3 3
4 2
5 2
7 1
8 2
9 2
6 3]
all the values must displays the number of occurences

Best Answer

c=unique(a);
b=[c, sum(bsxfun(@eq,a(:),c'))']
b =
3 3
4 2
5 2
6 3
7 1
8 2
9 2