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
categorical
function as described below.Bin continuous data using the
discretize
function. 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
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
categorical
rounds them off to five significant figures.For example,
categorical([1 1.23456789])
creates category names1
and1.2346
from these two values. To create categories from continuous numeric, duration, or datetime data, use thediscretize
function.If the input array has numeric, datetime, or duration values that are too closely spaced, then
categorical
cannot 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 about5e-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 thediscretize
function.
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