%% Method Function Handle with Multiple Inputs
% Load data containing patient information and create a table describing each patient's gender, systolic and diastolic blood pressure, height, and weight.

load patients
T = table(Gender,Systolic,Diastolic,Height,Weight)

% Grouping by gender, compute the correlation between patient height and weight and the correlation between systolic and diastolic blood pressure. Use the xcov function as the method to compute the correlation. The first two input arguments to xcov describe the data to correlate, the third argument describes the lag size, and the fourth argument describes the type of normalization. For each group computation, the x and y arguments passed into xcov are specified pairwise by variable from the two cell elements ["Height","Systolic"] and ["Weight","Diastolic"].

G = groupsummary(T,"Gender",@(x,y)xcov(x,y,0,'coeff'),{["Height","Systolic"],["Weight","Diastolic"]})

% Alternatively, if your data is in vector or matrix form instead of in a table, you can provide the data to correlate as the first input argument of groupsummary.

[G,GR,GC] = groupsummary({[Height,Systolic],[Weight,Diastolic]},Gender,@(x,y)xcov(x,y,0,'coeff'))

% Copyright 2020 The MathWorks, Inc.