B = addcats(A, names)
B = addcats(A, names, 'Before', anchor)
B = addcats(A, names, 'After', anchor)
| Parameter | Description |
|---|---|
| A | Input categorical array. |
| names | Category name or names to add. Names already present in A are ignored. |
| anchor | Existing category used as insertion point when Before or After is specified. |
| Parameter | Description |
|---|---|
| B | Categorical array with the same values as A and an updated category list. |
addcats appends categories to a categorical array without changing the stored elements.
For ordinal categorical arrays, the insertion position must be explicit because category order defines comparisons.
A = categorical({'red','blue'}); B = addcats(A, 'green'); categories(B)
A = categorical({'low','high'}, {'low','high'}, 'Ordinal', true); B = addcats(A, 'mid', 'Before', 'high'); categories(B)
| Version | Description |
|---|---|
| 2.0.0 | initial version |