%% Group Table Variables
% Compute the number of group elements from table data.
% Create a table containing information about five individuals.

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

% Count the number of elements in each group by gender.

G1 = groupcounts(T,'Gender')

% Count the number of elements in each group by gender and smoker status. By default, groupcounts suppresses groups with zero elements, so no groups are returned for female smokers or male nonsmokers.

G2 = groupcounts(T,{'Gender','Smoker'})

% To count all groups, including those with zero elements, specify the 'IncludeEmptyGroups' parameter with value true.

G3 = groupcounts(T,{'Gender','Smoker'},'IncludeEmptyGroups',true)

% Copyright 2018 The MathWorks, Inc.