islevel - Test for levels

Class

@categorical

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 two-dimensional 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.

Example

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

ismember, isundefined

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS