categorical.renamecats
categorical: B = renamecats (A, newnames)
categorical: B = renamecats (A, oldnames, newnames)
Rename categories in categorical array.
B = renamecats (A, newnames) renames all the
categories in A, without changing any of its values, with the names
specified in newnames. newnames can be specified as a 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, as long as it has the same number of elements as the categories
in A.
B = renamecats (A, oldnames, newnames)
renames the categories of A specified in oldnames with the
names specified in newnames. Both oldnames and
newnames can be a 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, as long as they have the same
number of elements. oldnames must specify a subset of existing
categories in A.
When renaming a single category, both oldnames and newnames can also be specified as character vectors.
Source Code: categorical
renamecats changes category names while leaving the values in place.
C = categorical ({'S'; 'M'; 'L'; 'S'}, {'S', 'M', 'L'})
C =
4x1 categorical array
S
M
L
S
Give a full set of new names (in category order) to rename them all ...
renamecats (C, {'Small', 'Medium', 'Large'})
ans =
4x1 categorical array
Small
Medium
Large
Small
... or rename only specific categories by old-name to new-name.
renamecats (C, {'S'}, {'Small'})
ans =
4x1 categorical array
Small
M
L
Small