%% Merge Two Categories into One
% Create a categorical array containing various colors.

A = categorical({'red';'blue';'pink';'red';'blue';'red'})

% A is a 6-by-1 categorical array.
%
% Display the categories of A.

categories(A)

% The three categories are in alphabetical order.
%
% Merge the categories red and pink into the category red. Specify red first in oldcats to use it as the merged category.

oldcats = {'red','pink'};
B = mergecats(A,oldcats)

% mergecats replaces the value pink from A(3) with red.
%
% Display the categories of B.

categories(B)

% B has two categories instead of three.
% Copyright 2012 The MathWorks, Inc.