categorical
Array that contains values assigned to categories
Description
categorical is a data type that assigns values to a finite
            set of discrete categories, such as High, Med, and
                Low. These categories can have a mathematical ordering that you
            specify, such as High > Med > Low, but it is not required. A
            categorical array provides efficient storage and convenient manipulation of nonnumeric
            data, while also maintaining meaningful names for the values. A common use of
            categorical arrays is to define groups of rows in a table.
Creation
To create a categorical array:
- Use the - categoricalfunction as described below.
- Bin continuous data using the - discretizefunction. Return the bins as a categorical array.
- Multiply two categorical arrays. The product is a categorical array whose categories are all possible combinations of the categories of the two operands. 
Syntax
Description
B = categorical( creates a
                    categorical array from the input array. The categories of the output array are
                    the sorted unique values from the input array.A)
B = categorical(
                    creates one category for each value in A,valueset)valueset. The
                    categories of B are in the same order as the values of
                        valueset.
You can use valueset to include categories for values not
                    present in A. Conversely, if A contains
                    any values not present in valueset, then the corresponding
                    elements of B are undefined.
B = categorical(
                    specifies options using one or more name-value arguments in addition to the
                    input arguments in previous syntaxes. For example, to indicate that the
                    categories have a mathematical ordering, set A,___,Name=Value)Ordinal to
                        true.
Input Arguments
Name-Value Arguments
Examples
Limitations
- If the input array is a numeric, datetime, or duration array, and you create category names from the values in the input, then - categoricalrounds them off to five significant figures.- For example, - categorical([1 1.23456789])creates category names- 1and- 1.2346from these two values. To create categories from continuous numeric, duration, or datetime data, use the- discretizefunction.
- If the input array has numeric, datetime, or duration values that are too closely spaced, then - categoricalcannot create category names from those values. In general, such values are too closely spaced if the difference between any two values in the input is less than about- 5e-5.- For example, - categorical([1 1.00001])cannot create category names from the two numeric values because the difference between them is too small. To create categories from continuous numeric, duration, or datetime data, use the- discretizefunction.
Tips
- For a list of functions that accept or return categorical arrays, see Categorical Arrays. 
Extended Capabilities
Version History
Introduced in R2013b
See Also
categories | discretize | iscategorical | addcats | times | NaN | missing

