Documentation Center

  • Trial Software
  • Product Updates

islevel

Class: categorical

Test for 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

I = islevel(levels,A)

Description

I = islevel(levels,A) returns a logical array I the same size as the string, cell array of strings, or 2-D character matrix levels. I is true (1) where the corresponding element of levels is the label of a level in the categorical array A, even if the level contains no elements. I is false (0) otherwise.

Examples

Display age levels in the data in hospitl.mat, before and after dropping occupied levels:

load hospital
edges = 0:10:100;
labels = strcat(num2str((0:10:90)','%d'),{'s'});
disp(labels')
 '0s' '10s' '20s' '30s' '40s' '50s' '60s' '70s' '80s' '90s'

AgeGroup = ordinal(hospital.Age,labels,[],edges);
I = islevel(labels,AgeGroup);
disp(I')
 1  1  1  1  1  1  1  1  1  1

AgeGroup = droplevels(AgeGroup);
I = islevel(labels,AgeGroup);
disp(I')
 0  0  1  1  1  1  0  0  0  0

See Also

|

Was this topic helpful?