| Statistics Toolbox™ | ![]() |
C = levelcounts(A)
C = levelcounts(A,dim)
C = levelcounts(A) for a categorical vector A counts the number of elements in A equal to each of the possible levels in A. The output is a vector C containing those counts, and has as many elements as A has levels. For matrix A, C is a matrix of column counts. For N-dimensional arrays, levelcounts operates along the first nonsingleton dimension.
C = levelcounts(A,dim) operates along the dimension dim.
Count the number of patients in each age group in the data in hospital.mat:
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
c = levelcounts(AgeGroup);
disp(c')
0 0 15 41 42 2 0 0 0 0
AgeGroup = droplevels(AgeGroup);
I = islevel(labels,AgeGroup);
disp(I')
0 0 1 1 1 1 0 0 0 0
c = levelcounts(AgeGroup);
disp(c')
15 41 42 2![]() | kurtosis | leverage | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |