| Statistics Toolbox™ | ![]() |
I = ismember(A,levels)
[I,IDX] = ismember(A,levels)
I = ismember(A,levels) returns a logical array I the same size as the categorical array A. I is true (1) where the corresponding element of A is one of the levels specified by the labels in the categorical array, cell array of strings, or two-dimensional character array levels. I is false (0) otherwise.
[I,IDX] = ismember(A,levels) also returns an array of indices IDX containing the highest absolute index in levels for each element in A whose level is a member of levels, and 0 if there is no such index.
For nominal data:
load hospital
sex = hospital.Sex; % Nominal
smokers = hospital.Smoker; % Logical
I = ismember(sex(smokers),'Female');
I(1:5)
ans =
0
1
0
0
0The use of ismember above is equivalent to:
I = (sex(smokers) == 'Female');
For ordinal data:
load hospital
edges = 0:10:100;
labels = strcat(num2str((0:10:90)','%d'),{'s'});
AgeGroup = ordinal(hospital.Age,labels,[],edges);
I = ismember(AgeGroup(1:5),{'20s','30s'})
I =
1
0
1
0
0![]() | islevel | isundefined | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |