%% Use Unique Values from Two Grouping Variables
% Calculate mean blood pressures for groups of patients, and display the results in a table. To define the groups of patients, use the additional output arguments from findgroups.
% Load blood pressure readings, gender, and smoking data for 100 patients from the data file patients.mat.

load patients
whos Systolic Diastolic Gender Smoker

%
% Specify groups using gender and smoking information about the patients. Calculate mean blood pressure for each group. The values across the output arguments gender and smoker define the groups that findgroups finds in the grouping variables.

[G,gender,smoker] = findgroups(Gender,Smoker);
meanSystolic = splitapply(@mean,Systolic,G);
meanDiastolic = splitapply(@mean,Diastolic,G);

%
% Create a table with the mean blood pressure for each group of patients.

T = table(gender,smoker,meanSystolic,meanDiastolic)

% Copyright 2015 The MathWorks, Inc.