categorical

Methods

Method Reference: categorical.countcats

categorical: N = countcats (C)
categorical: N = countcats (C, dim)

Count occurrences of categories in a categorical array.

N = countcats (C) returns the number of elements for each category in C. If C is a vector, N is also a vector with one element for each category in C. If C is a matrix, N is a matrix with each column containing the category counts from each column of C. For multidimensional arrays, countcats operates along the first non-singleton dimension.

N = countcats (C, dim) operates along the dimension dim.

Source Code: categorical

Example: 1

countcats tallies how many elements fall in each category, in category order. Categories with no elements are counted as zero, so the result lines up one-to-one with categories.

 C = categorical ({'M'; 'S'; 'L'; 'M'; 'S'; 'M'}, {'S', 'M', 'L', 'XL'})
C =
  6x1 categorical array

    M    
    S    
    L    
    M    
    S    
    M
 categories (C)
ans =
  4x1 cell array

    {'S' }    
    {'M' }    
    {'L' }    
    {'XL'}
 countcats (C)
ans =

   2
   3
   1
   0