www.gusucode.com > stats 源码程序 matlab案例代码 > stats/WorkWithDatasetsUsingFunctionHandlesExample.m
%% Work With Datasets Using Function Handles % Use function handles to compute the mean and plot a histogram of selected % variables in a dataset array. % Copyright 2015 The MathWorks, Inc. %% % Load the sample data. load hospital %% % Use |datasetfun| to compute the means of the |Weight| and |BloodPressure| % variables, and store the results in a dataset array. stats = datasetfun(@mean,hospital,... 'DataVars',{'Weight','BloodPressure'},... 'UniformOutput',false) %% % The variable |BloodPressure| contains two columns: One for the systolic % measurement, and one for the diastolic measurement. %% % Display the mean of the blood pressure variable. stats{2} %% % Plot a histogram of the blood pressure variable. datasetfun(@hist,hospital,... 'DataVars','BloodPressure',... 'UniformOutput',false); title('{\bf Blood Pressure}') legend('Systolic','Diastolic','Location','N')