droplevels

(Not Recommended) Drop levels from a nominal or ordinal array

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

Description

example

B = droplevels(A) drops unused levels from the nominal or ordinal array A. The array B has the same size, type, and values as A, but has a list of potential levels that includes only those present in some element of A.

B = droplevels(A,oldlevels) removes the specified levels oldlevels from A.

droplevels removes levels, but does not remove elements. Elements of B that correspond to elements of A having levels in oldlevels all have an undefined level.

Examples

collapse all

Bin patient ages into ordinal levels corresponding to 10-year intervals.

load hospital
edges = 0:10:100;
labels = strcat(num2str((0:10:90)','%d'),{'s'});
A = ordinal(hospital.Age,labels,[],edges);
getlabels(A)
ans = 1x10 cell array
  Columns 1 through 7

    {'0s'}    {'10s'}    {'20s'}    {'30s'}    {'40s'}    {'50s'}    {'60s'}

  Columns 8 through 10

    {'70s'}    {'80s'}    {'90s'}

Drop any levels that have no patients in them.

A = droplevels(A);
getlabels(A)
ans = 1x4 cell array
    {'20s'}    {'30s'}    {'40s'}    {'50s'}

Input Arguments

collapse all

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

Levels to remove from the 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.

Introduced in R2007a