countcats
Number of elements in each category of a categorical array.
Category: Language Fundamentals > Data Types
Syntax
N = countcats(C)
Counts elements per category, along the first non-singleton dimension.
N = countcats(C, dim)
Counts along dimension dim.
Description
Categories with no elements are reported with 0. Undefined elements are not counted. The order of N follows categories(C), so the two outputs can be displayed side by side.
Input arguments
C- categorical array.
dim- Dimension to count along.
Output arguments
N- Counts in category order. For a vector, one number per category.
Example
Counting labels
c = categorical({'a','b','a','c'});
categories(c)'
countcats(c)
Output
ans = 1×3 cell
{'a'} {'b'} {'c'}
ans = 1×3
2 1 1