The easiest way is to use accumarray
:
accumarray(A(:,1),A(:,2),[],@numel);
Taken from Matlab help:
accumarray groups elements from a data set and applies a function to each group. A = accumarray(subs,val) creates an array A by accumulating elements of the vector val using the elements of subs as indices. The position of an element in subs determines which value of vals it selects for the accumulated vector; the value of an element in subs determines the position of the accumulated vector in the output.
In our case, we need to group all of the elements and count their number. numel
does the counting.
By the way, you don't need the second column of your data at all:
accumarray(A(:,1),zeros(size(A(:,1))),[],@numel)