Main Content

addlevels

(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.

Description

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.

example

Examples

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);
getlevels(species)
ans = 1x3 nominal
     setosa      versicolor      virginica 

Add two additional species.

species = addlevels(species,{'spuria','ruthenica'});
getlevels(species)
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.

sum(species=='spuria')
ans = 
0
sum(species=='ruthenica')
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