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.


Arrays for nominal data


Nominal data are discrete, nonnumeric values that do not have a natural ordering. nominal array objects provide efficient storage and convenient manipulation of such data, while also maintaining meaningful labels for the values.

You can manipulate nominal arrays much like ordinary numeric arrays, including subscripting, concatenating, and reshaping. It can be useful to use nominal arrays as grouping variables when the elements indicate the group an observation belongs to.


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.


Create nominal arrays using the nominal function.


expand all

This property is read-only.

Level labels, specified as a cell array of character vectors. Access labels using getlabels.

Data Types: cell

This property is read-only.

Label for undefined levels, specified as '<undefined>'. You can find undefined elements in categorical arrays using isundefined.

Object Functions

addlevelsAdd levels to nominal or ordinal arrays
droplevelsDrop levels from a nominal or ordinal array
getlabelsAccess categorical array labels
getlevelsAccess categorical array levels
islevelDetermine if levels are in nominal or ordinal array
levelcountsElement counts by level of a nominal or ordinal array
mergelevelsMerge levels of nominal or ordinal arrays
reorderlevelsReorder levels of nominal or ordinal arrays
setlabelsAssign labels to levels of nominal or ordinal arrays

You can also use many other MATLAB array functions with categorical arrays. The following is a partial list. For a complete list, see Other MATLAB Functions Supporting Nominal and Ordinal Arrays.

doubleDouble-precision arrays
histogramHistogram plot
isequalDetermine array equality
isundefinedFind undefined elements in categorical array
piePie chart
summaryPrint summary of table, timetable, or categorical array
timesElement-wise multiplication


expand all

Create a nominal array from data in a cell array.

colors = nominal({'r','b','g';'g','r','b';'b','r','g'},...
colors = 

  3x3 nominal array

     red        blue      green 
     green      red       blue  
     blue       red       green 

Identify the elements in colors that are members of the level 'red'. A value of 1 in the resulting array indicates that the corresponding element of colors is a member of 'red'.

colors == 'red'
ans =

  3x3 logical array

   1   0   0
   0   1   0
   0   1   0

Identify the elements of colors that are members of either 'red' or 'blue'.

ismember(colors,{'red' 'blue'})
ans =

  3x3 logical array

   1   1   0
   0   1   1
   1   1   0

Merge the elements of the 'red' and 'blue' levels into a new level labeled 'purple'.

colors = mergelevels(colors,{'red','blue'},'purple')
colors = 

  3x3 nominal array

     purple      purple      green  
     green       purple      purple 
     purple      purple      green  

Display the levels of colors.

ans = 

  1x2 nominal array

     purple      green 

Summarize the number of elements in each level. By default, summary returns counts for each column of the input array.

     purple      2      3      1 
     green       1      0      2 

Create a pie chart for the data in colors.


Was this topic helpful?