www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/UseTwoGroupingVariablesToSplitDataExample.m

    %% Use Two Grouping Variables to Split Data
% Calculate mean blood pressures for groups of patients from measurements grouped 
% by gender and status as a smoker.
%
% Load blood pressure readings, gender, and smoking data for patients from the 
% data file |patients.mat|.

% Copyright 2015 The MathWorks, Inc.

load patients
whos Systolic Diastolic Gender Smoker

%%
% Specify groups using gender and smoking information about the patients. |G| 
% contains integers from one to four because there are four possible combinations
% of values from |Smoker| and |Gender|.
G = findgroups(Smoker,Gender);
G(1:10)

%%
% Calculate the mean blood pressure for each group.
meanSystolic = splitapply(@mean,Systolic,G);
meanDiastolic = splitapply(@mean,Diastolic,G);
mBP = [meanSystolic,meanDiastolic]