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 ordinal data


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

You can manipulate ordinal arrays much like ordinary numeric arrays, including subscripting, concatenating, and reshaping. It can be useful to use ordinal 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 ordinal arrays using the ordinal 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 an ordinal array from integer data.

quality = ordinal([1 2 3; 3 2 1; 2 1 3],{'low' 'medium' 'high'})
quality = 

  3x3 ordinal array

     low         medium      high 
     high        medium      low  
     medium      low         high 

Identify the elements in quality that are members of a level that is greater than or equal to 'medium'. A value of 1 in the resulting array indicates that the corresponding element of quality is in this category.

quality >= 'medium'
ans =

  3x3 logical array

   0   1   1
   1   1   0
   1   0   1

Identify the elements of quality that are members of either 'low' or 'high'.

ismember(quality,{'low' 'high'})
ans =

  3x3 logical array

   1   0   1
   1   0   1
   0   1   1

Merge the elements of the 'medium' and 'high' levels into a new level labeled 'ok'.

quality = mergelevels(quality,{'medium','high'},'ok')
quality = 

  3x3 ordinal array

     low      ok       ok  
     ok       ok       low 
     ok       low      ok  

Display the levels of quality.

ans = 

  1x2 ordinal array

     low      ok 

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

     low      1      1      1 
     ok       2      2      2 
Was this topic helpful?