Documentation Center

  • Trial Software
  • Product Updates


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.


I = islevel(levels,A)


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.


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'});
 '0s' '10s' '20s' '30s' '40s' '50s' '60s' '70s' '80s' '90s'

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

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

See Also


Was this topic helpful?