This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Categories of categorical array


C = categories(A)



C = categories(A) returns a cell array of character vectors containing the categories of the categorical array, A.


collapse all

Create a categorical array, A.

A = categorical({'plane' 'car' 'train' 'car' 'plane'})
A = 1x5 categorical array
     plane      car      train      car      plane 

A is a 1-by-5 categorical array.

Display the categories of A.

C = categories(A)
C = 3x1 cell array
    {'car'  }

Since you created A by specifying only an input array, the categories appear in alphabetical order.

Create an ordinal categorical array.

A = categorical({'medium' 'large'; 'small' 'xlarge'; 'large' 'medium'},...
    {'small' 'medium' 'large' 'xlarge'},'Ordinal',true)
A = 3x2 categorical array
     medium      large  
     small       xlarge 
     large       medium 

A is a 3-by-2 ordinal categorical array.

Display the categories of A.

C = categories(A)
C = 4x1 cell array
    {'small' }
    {'large' }

The categories appear in the order in which you specified them. Since A is ordinal, the categories have the mathematical ordering small < medium < large < xlarge.

Input Arguments

collapse all

Categorical array, specified as a vector, matrix, or multidimensional array.


  • C includes all categories in A, even if A does not contain any data from a category. To see the unique values in A, use unique(A).

  • The order of the categories listed in C is the same order used by functions, such as summary and histogram. To change the order of the categories, use reordercats.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2013b