C = categorical(A)
C = categorical(A, valueset)
C = categorical(A, valueset, categoryNames)
C = categorical(..., 'Ordinal', tf)
C = categorical(..., 'Protected', tf)
| Parameter | Description |
|---|---|
| A | Input values. Text, string, numeric, logical, or categorical input is accepted. |
| valueset | Explicit set of input values that define categories. |
| categoryNames | Names assigned to the categories defined by valueset. |
| tf | Logical scalar that enables ordinal ordering or category protection. |
| Parameter | Description |
|---|---|
| C | Categorical array with the same size as A. |
categorical stores repeated values as integer category codes plus a category name list.
Values that are empty text, missing strings, or not found in an explicit valueset become undefined categorical elements.
Ordinal arrays use category order for relational comparisons. Ordinal arrays are protected automatically.
contains, startsWith, endsWith and matches accept a categorical array as input: they test the category name of each element against the pattern (text, cell of text, string array or pattern object, with the optional 'IgnoreCase' option) and return a logical array of the same size. Undefined elements return false. Each category name is tested only once.
Concatenating a categorical array with text (["z" C], ['z' C], [{'z'} C]) or missing converts the other operands: the result keeps the categories of the first categorical operand and adds new values in operand order; empty text and missing are undefined. Ordinal and protected arrays reject values that are not already categories, and other classes (numeric, logical, string arrays with several elements) are rejected.
C = categorical({'red','blue','red'}); categories(C)
C = categorical({'low','high','mid'}, {'low','mid','high'}, 'Ordinal', true); C > 'mid'
C = categorical({'winter storm','fire','Thunder Storm',''}); contains(C, "storm", 'IgnoreCase', true)
| Version | Description |
|---|---|
| 2.0.0 | initial version |