%% Category Counts of Categorical Vector
% Create a 1-by-5 categorical vector.

A = categorical({'plane' 'car' 'train' 'car' 'plane'})

%
% A has three categories. To list the categories and their order, use the categories function. Every element of A belongs to one of the categories listed by the call to categories.

categories(A)

%
% Find the number of elements in each category of A.

B = countcats(A)

% The first element in B corresponds to the first category of A, which is car. The second element in B corresponds to the second category of A, which is plane. The third element of B corresponds to the third category of A, which is train.
% Since A is a row vector, countcats returns a row vector.
% Copyright 2012 The MathWorks, Inc.