addcats
Adds new categories to a categorical array without changing its values.
Category: Language Fundamentals > Data Types
Syntax
B = addcats(A, newcats)
Appends the categories newcats to the end of the category list.
Description
No element changes: the new categories simply become valid values that no element uses yet. This matters before assigning a value that is not in the category list, which would otherwise raise an error, and for tables like those from countcats, where unused categories appear with a zero count.
Input arguments
A- Categorical array.
newcats- Name or cell array or string array of names that are not yet categories.
Output arguments
B- Categorical array equal to
Abut with the extra categories.
Example
Add an unused category
c = categorical({'a', 'b', 'a'});
d = addcats(c, 'z');
categories(d)'
countcats(d)
Output
ans = 1×3 cell
{'a'} {'b'} {'z'}
ans = 1×3
2 1 0