%% Find Bin Counts
% Create a vector of subscripts, subs.

subs = [1; 2; 4; 2; 4]

%
% Use accumarray with val = 1 to count the number of identical subscripts in subs.

A = accumarray(subs,1)

% The result is a vector of bin counts. You can obtain the same answer with histcounts(subs,'BinMethod','integers'). However, accumarray also can compute bin counts over higher dimensional grids.
% Copyright 2012 The MathWorks, Inc.