Categorical Arrays

Arrays of qualitative data with values from a finite set of discrete, nonnumeric data

categorical is a data type to store data with values from a finite set of discrete categories. These categories can have a natural order, 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. You can use categorical arrays in a table to select groups of rows. For more information see Create Categorical Arrays or watch Tables and Categorical Arrays.

Functions

categoricalArray that contains values assigned to categories
iscategoricalDetermine whether input is categorical array
discretizeGroup data into bins or categories
categoriesCategories of categorical array
iscategoryTest for categorical array categories
isordinalDetermine whether input is ordinal categorical array
isprotectedDetermine whether categories of categorical array are protected
addcatsAdd categories to categorical array
mergecatsMerge categories in categorical array
removecatsRemove categories from categorical array
renamecatsRename categories in categorical array
reordercatsReorder categories in categorical array
setcatsSet categories in categorical array
summaryPrint summary of table, timetable, or categorical array
countcatsCount occurrences of categorical array elements by category
isundefinedFind undefined elements in categorical array

Examples and How To

Create Categorical Arrays

This example shows how to create a categorical array.

Convert Text in Table Variables to Categorical

This example shows how to convert a variable in a table from a cell array of character vectors to a categorical array.

Compare Categorical Array Elements

Use relational operations with a categorical array.

Combine Categorical Arrays

Use concatenation to combine categorical arrays.

Combine Categorical Arrays Using Multiplication

Use multiplication to combine categorical arrays, including ordinal categorical arrays and arrays with undefined elements.

Plot Categorical Data

Plot data from a categorical array.

Access Data Using Categorical Arrays

Search, select, and delete elements from categorical arrays.

Work with Protected Categorical Arrays

This example shows how to work with a categorical array with protected categories.

Concepts

Advantages of Using Categorical Arrays

Categorical arrays provide a natural representation of data, mathematical ordering of character vectors, and efficient memory usage.

Ordinal Categorical Arrays

Ordinal categorical arrays have a mathematical ordering to their categories. Use an ordinal categorical array if you want to use the functions min, max, or relational operations, such as greater than and less than.

Core Functions Supporting Categorical Arrays

Many functions in MATLAB® operate on categorical arrays in much the same way that they operate on other arrays. A few of these functions might exhibit special behavior when operating on a categorical array.