%% Multiple Grouping Vectors for Vector Input
% Compute the group counts for four groups based on their gender and smoker status.
% Store patient information as three vectors of different types.

Gender = ["male";"female";"male";"female";"male"];
Smoker = logical([1;0;1;0;1]);
Weight = [176;163;131;133;119];

% Grouping by gender and smoker status, compute the group counts. B contains the counts for each group. BG is a cell array containing two vectors that describe the groups as you look at their elements rowwise. For instance, the first row of BG{1} says that the patients in the first group are female, and the first row of BG{2} says that they are nonsmokers. The count for that group is 2, found in the corresponding row of B.

[B,BG] = groupcounts({Gender,Smoker},'IncludeEmptyGroups',true);
B
BG{1}
BG{2}

% Copyright 2018 The MathWorks, Inc.