使用 patients.mat 文件中数据的数组创建一个包含多个表的表。显示前三行。
load patients
Personal_Data = table(Gender,Age);
BMI_Data = table(Height,Weight);
BloodPressure = table(Systolic,Diastolic);
T1 = table(LastName,Personal_Data,BMI_Data,BloodPressure);
head(T1,3)
ans=3×4 table
LastName Personal_Data BMI_Data BloodPressure
Gender Age Height Weight Systolic Diastolic
____________ _________________ ________________ _____________________
{'Smith' } {'Male' } 38 71 176 124 93
{'Johnson' } {'Male' } 43 69 163 109 77
{'Williams'} {'Female'} 38 64 131 125 83
将 BloodPressure 指定为要拆分的变量。
T2 = splitvars(T1,'BloodPressure');
head(T2,3)
ans=3×5 table
LastName Personal_Data BMI_Data Systolic Diastolic
Gender Age Height Weight
____________ _________________ ________________ ________ _________
{'Smith' } {'Male' } 38 71 176 124 93
{'Johnson' } {'Male' } 43 69 163 109 77
{'Williams'} {'Female'} 38 64 131 125 83
要按名称指定多个变量,请使用字符向量元胞数组。
T3 = splitvars(T1,{'BMI_Data','BloodPressure'});
head(T3,3)
ans=3×6 table
LastName Personal_Data Height Weight Systolic Diastolic
Gender Age
____________ _________________ ______ ______ ________ _________
{'Smith' } {'Male' } 38 71 176 124 93
{'Johnson' } {'Male' } 43 69 163 109 77
{'Williams'} {'Female'} 38 64 131 125 83
要按位置指定变量,请使用数值数组。
T4 = splitvars(T1,[2 4]);
head(T4,3)
ans=3×6 table
LastName Gender Age BMI_Data Systolic Diastolic
Height Weight
____________ __________ ___ ________________ ________ _________
{'Smith' } {'Male' } 38 71 176 124 93
{'Johnson' } {'Male' } 43 69 163 109 77
{'Williams'} {'Female'} 38 64 131 125 83