This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Advantages of Using Categorical Arrays


The nominal and ordinal array data types might be removed in a future release. To represent ordered and unordered discrete, nonnumeric data, use the MATLAB® categorical data type instead.

Manipulate Category Levels

When working with categorical variables and their levels, you’ll encounter some typical challenges. This table summarizes the functions you can use with categorical arrays to manipulate category levels. For additional functions, type methods nominal or methods ordinal at the command line, or see the nominal and ordinal reference pages.

Add new category levels addlevels
Drop category levelsdroplevels
Combine category levelsmergelevels
Reorder category levelsreorderlevels
Count the number of observations in each categorylevelcounts
Change the label or name of category levelssetlabels
Create an interaction factortimes
Find observations that are not in a defined categoryisundefined

Analysis Using Categorical Arrays

You can use categorical arrays in a variety of statistical analyses. For example, you might want to compute descriptive statistics for data grouped by the category levels, conduct statistical tests on differences between category means, or perform regression analysis using categorical predictors.

Statistics and Machine Learning Toolbox™ functions that accept a grouping variable as an input argument accept categorical arrays. This includes descriptive functions such as:

You can also use categorical arrays as input arguments to analysis functions and methods based on models, such as:

When you use a categorical array as a predictor in these functions, the fitting function automatically recognizes the categorical predictor, and constructs appropriate dummy indicator variables for analysis. Alternatively, you can construct your own dummy indicator variables using dummyvar.

Reduce Memory Requirements

The levels of categorical variables are often defined as text, which can be costly to store and manipulate in a cell array of character vectors or char array. Categorical arrays separately store category membership and category labels, greatly reducing the amount of memory required to store the variable.

For example, load some sample data:

The variable species is a cell array of character vectors requiring 19,300 bytes of memory.

Convert species to a nominal array:

species = nominal(species);

There is a 95% reduction in memory required to store the variable.

See Also


Related Examples

More About

Was this topic helpful?