Documentation Center

  • Trial Software
  • Product Updates

reorderlevels

Class: categorical

Reorder levels

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.

Syntax

B = reorderlevels(A,newlevels)

Description

B = reorderlevels(A,newlevels) reorders the levels of the categorical array A. newlevels is a cell array of strings or a 2-D character matrix that specifies the new order. newlevels must be a reordering of getlabels(A).

The order of the levels of an ordinal array has significance for relational operators, minimum and maximum, and for sorting.

Examples

Reorder hockey standings:

standings = ordinal(1:3,{'Leafs','Canadiens','Bruins'});
getlabels(standings)
ans = 
    'Leafs'  'Canadiens'  'Bruins'

standings = reorderlevels(standings,...
            {'Canadiens','Leafs','Bruins'});
getlabels(standings)
ans = 
    'Canadiens'  'Leafs'  'Bruins'

See Also

| | | |

Was this topic helpful?