%% Count of Unique Elements
% Find the unique elements in a vector and then use accumarray to count the number of times each unique element appears.
%
% Create a vector of random integers from 1 through 5.

a = randi([1 5],200,1);

%
% Find the unique elements in the vector. Return the index vectors ia and ic.

[C,ia,ic] = unique(a);

%
% Count the number of times each element in C appears in a. Specify ic as the first input to accumarray and 1 as the second input so that the function counts repeated subscripts in ic. Summarize the results.

a_counts = accumarray(ic,1);
value_counts = [C, a_counts]

% Copyright 2012 The MathWorks, Inc.