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 specify groups of rows in a table.
Creation
Syntax
Description
B = categorical(
creates a
categorical array from the array A
)A
. The categories of
B
are the sorted unique values from
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(
creates a categorical array with additional options specified by one or more
A
,___,Name,Value
)Name,Value
pair arguments. You can include any of the
input arguments in previous syntaxes.
For example, to indicate that the categories have a mathematical ordering,
specify 'Ordinal',true
.
Input Arguments
Examples
Tips
For a list of functions that accept or return categorical arrays, see Categorical Arrays.
If the input array has numeric, datetime, or duration values that are too close together, then the
categorical
function truncates them to duplicate values. For example,categorical([1 1.00001])
truncates the second element of the input array. To create categories from numeric data, use thediscretize
function.
Alternatives
You also can group numeric data into categories using discretize
.
Extended Capabilities
Version History
Introduced in R2013b