categorical.mergecats
categorical: B = mergecats (A, oldcats)
categorical: B = mergecats (A, oldcats, newcat)
Merge categories in categorical array.
B = mergecats (A, oldcats) merges two or more
categories specified by oldcats into a single category with the
same name as oldcats(1). In case of ordinal categorical
arrays, the categories listed in oldcats must be in consecutive
order. All elements of A corresponding to the categories listed in
oldcats are re-indexed to correspond to oldcats(1) in
B.
B = mergecats (A, oldcats, newcat) merges
the categories listed in oldcats into a single new category named
as specified by newcat.
newcat must be either a character vector, a cellstr scalar or a
string scalar. oldcats can be string array, a cell array of
character vectors, or any type of array that can be converted to a cell
array of character vectors with the cellstr function. Any names
in oldcats that do not reference an existing category are ignored.
Source Code: categorical
mergecats collapses several categories into one, relabelling every element that used them — a quick way to coarsen a classification.
C = categorical ({'S'; 'M'; 'L'; 'S'; 'M'}, {'S', 'M', 'L'})
C =
5x1 categorical array
S
M
L
S
M
Fold S and M together into a single small category.
mergecats (C, {'S', 'M'}, 'small')
ans =
5x1 categorical array
small
small
L
small
small