MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Male true 181.14


T.gender contains categorical values, and T.smoker contains logical values. The data
types of these table variables match the data types of Gender and Smoker respectively.


Calculate body mass index (BMI) for the four groups of patients. Define a function that
takes Height and Weight as its two input arguments, and that calculates BMI.


meanBMIfcn = @(h,w)mean((w ./ (h.^2)) * 703);
BMI = splitapply(meanBMIfcn,Height,Weight,G)


BMI = 4×1


21.6721
21.6686
26.5775
26.4584


Group Patients Based on Self-Reports


Calculate the fraction of patients who report their health as either Poor or Fair. First,
use splitapply to count the number of patients in each group: female nonsmokers,
female smokers, male nonsmokers, and male smokers. Then, count only those patients
who report their health as either Poor or Fair, using logical indexing on S and G. From
these two sets of counts, calculate the fraction for each group.


[G,gender,smoker] = findgroups(Gender,Smoker);
S = SelfAssessedHealthStatus;
I = ismember(S,{'Poor','Fair'});
numPatients = splitapply(@numel,S,G);
numPF = splitapply(@numel,S(I),G(I));
numPF./numPatients


ans = 4×1


0.2500
0.3846
0.3077
0.1429


Compare the standard deviation in Diastolic readings of those patients who report
Poor or Fair health, and those patients who report Good or Excellent health.


Split Data into Groups and Calculate Statistics
Free download pdf