加载患者数据
加载从 100 位患者收集的样本数据。
load patients
将 Gender 和 SelfAssessedHealthStatus 转换为分类数组。
Gender = categorical(Gender);
SelfAssessedHealthStatus = categorical(SelfAssessedHealthStatus);
whos
Name Size Bytes Class Attributes
Age 100x1 800 double
Diastolic 100x1 800 double
Gender 100x1 330 categorical
Height 100x1 800 double
LastName 100x1 11616 cell
Location 100x1 14208 cell
SelfAssessedHealthStatus 100x1 560 categorical
Smoker 100x1 100 logical
Systolic 100x1 800 double
Weight 100x1 800 double
计算平均体重
使用 Smoker 变量将患者划分为非吸烟者和吸烟者。计算每个组的平均体重。
[G,smoker] = findgroups(Smoker);
meanWeight = splitapply(@mean,Weight,G)
meanWeight = 2×1
149.9091
161.9412
findgroups 函数会返回 G(从 Smoker 创建的组数目向量)。splitapply 函数会使用 G 将 Weight 分

使用MATLAB将数据按特定条件分组,如吸烟者和非吸烟者的体重,计算平均体重和BMI,同时分析健康状况对血压读数的影响。
最低0.47元/天 解锁文章
1078

被折叠的 条评论
为什么被折叠?



