A=[ ...
0 0 0 0 0
2 5 0 0 0
0 0 2 5 0
0 0 0 0 2 ];
A = shape(A, 1,[]);
c = 1:max(a);
B=histc(a,C)
result
B =
0 3 0 0 2
Also, when you say histogram, everyone will understand what you mean, O(∩_∩)O~