%% Alphabetize Categories of Nonordinal Categorical Array
% Create two categorical arrays, X and Y.

X = categorical({'frog';'cat';'cat';'ant';'frog'})

Y = categorical({'deer';'bear';'eagle';'deer'})

% X is a 5-by-1 categorical array. The categories of X are the sorted unique values from the array: {'ant';'cat';'frog'}.
% Y is a 4-by-1 categorical array. The categories of Y are the sorted unique values from the array: {'bear';'deer';'eagle'}.
%
% Concatenate X and Y into a single categorical array, A.

A = [X;Y]

% vertcat appends the values from Y to the values from X.
%
% List the categories of the categorical array, A.

acats = categories(A)

% vertcat appends the categories of Y to the categories from X. The categories of A are not in alphabetical order.
%
% Reorder the categories of A into alphabetical order.

B = reordercats(A)

% The output categorical array, B, has the same elements in the same order as the input categorical array, A.
%
% List the categories of the categorical array, B.

bcats = categories(B)

% The categories of B are in alphabetical order.
% Copyright 2012 The MathWorks, Inc.