MATLAB: Can this loop be vectorized

for loopvectorization

I am trying to make a function for an histogram to explain the concept to students, is possible to vectorize this loop?
[x,y]=size(A);
freq=zeros(256,1);
for i=1:x
for j=1:y
value=A(i,j);
freq(value+1)=freq(value+1)+1;
end
end
thanks in advance.

Best Answer

Very simply with:
freq = accumarray(A(:), 1, [256, 1]);