The countcats function
MATLAB provides the countcats function to count the categories in a categorical array. This function only works on categorical arrays and will throw an error on ordinary arrays or vectors. The syntax of the same is:
cnt = countcats(<categorical-array-name>)
The syntax is simple as the function takes the required parameter as the name of the categorical array whose categories need to be counted. In case of multidimensional categorical arrays, we can also pass the dimension along which we need the category count. We shall now see the same in example.
Count Occurrences of Categorical Array Elements By Category
Categorical arrays are arrays that stores data of categorical type in MATLAB. The categorical data is pre defined by a finite set of discrete values/categories from which any category can be selected multiple times.
In this article, we shall learn how to count the occurrences of discrete categories in a categorical array in MATLAB. This can come handy when we need to count the number of times a category repeats in our data or we can also use this method to find whether or not we have unique entries in some data.
Contact Us