%% Category Counts of Array Containing Undefined Elements
% Create a 6-by-1 categorical array, A, from a numeric array.

valueset = 1:3;
catnames = {'red' 'green' 'blue'};

A = categorical([1;3;2;1;3;1],valueset,catnames)

%
% Remove the blue category.

A = removecats(A,'blue')

% A has two categories, red and green. Elements of A that were from the blue category are now undefined.
%
% 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. The value, red, occurs three times in A.
% The second element in B corresponds to the second category of A. The value, green, occurs once in A.
% countcats does not return any information on undefined elements.
%
% Use the summary function to view the number of undefined elements in addition to the number of elements in each category of A.

summary(A)

% Copyright 2012 The MathWorks, Inc.