%% Category Counts of Each Row in Array
% Create a 3-by-2 categorical array, A, from a numeric array.

valueset = 1:3;
catnames = {'red' 'green' 'blue'};

A = categorical([1 3; 2 1; 3 1],valueset,catnames)

% A has three categories, red, green, and blue.
%
% Find the category counts of A along the second dimension.

B = countcats(A,2)

% The first column of B corresponds to the first category of A. The value, red, occurs once in the first row of A, once in the second row, and once in the third row.
% The second column of B corresponds to the second category of A. The value, green, occurs in only one element. It occurs in the second row of A.
% The third column of B corresponds to the third category of A. The value, blue, occurs once in the first row of A and once in the third row.
% Copyright 2012 The MathWorks, Inc.