%% Remove All Unused Categories
% Create a categorical array representing political parties of four people.

A = categorical({'republican' 'democrat' 'democrat' 'republican'},...
    {'democrat' 'republican' 'independent'})

% A is a 1-by-4 categorical array.
%
% Summarize the categorical array, A.

summary(A)

% A has three categories. democrat appears twice in the array, republican appears twice in the array, and independent is unused.
%
% Remove the unused category, independent.

B = removecats(A)

% B has the same values as A.
%
% Display the categories of B.

categories(B)

% B has fewer categories than A.
% Copyright 2012 The MathWorks, Inc.