Main Content


(Not Recommended) Add levels to nominal or ordinal arrays

The nominal and ordinal array data types are not recommended. To represent ordered and unordered discrete, nonnumeric data, use the Categorical Arrays data type instead.



B = addlevels(A,newlevels) adds new levels specified by newlevels to the nominal or ordinal array A. addlevels adds the new levels at the end of the list of possible levels in A, but does not modify the value of any element. B does not contain elements at the new levels.


collapse all

Add levels for additional species to Fisher's iris data.

Create a nominal array of the existing species in Fisher's iris data.

load fisheriris
species = nominal(species);
ans = 1x3 nominal
     setosa      versicolor      virginica 

Add two additional species.

species = addlevels(species,{'spuria','ruthenica'});
ans = 1x5 nominal
     setosa      versicolor      virginica      spuria      ruthenica 

Even though there are new levels, there are no elements in species that are in these new levels.

ans = 0
ans = 0

Input Arguments

collapse all

Nominal or ordinal array, specified as a nominal or ordinal array object created with nominal or ordinal.

Levels to add to the input nominal or ordinal array, specified as a string array, a cell array of character vectors, or a 2-D character matrix.

Data Types: char | string | cell

Output Arguments

collapse all

Nominal or ordinal array, returned as a nominal or ordinal array object.

Version History

Introduced in R2007a