%% Multiple Grouping Vectors for Vector Input
% Compute the mean weights 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 mean weights. B contains the mean for each group (NaN for empty groups). 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. Finally, BC contains the number of members in each group for the corresponding groups in BG.

[B,BG,BC] = groupsummary(Weight,{Gender,Smoker},'mean','IncludeEmptyGroups',true);
B
BG{1}
BG{2}
BC

% Copyright 2018 The MathWorks, Inc.