'Smith' 38 'Male' true 71 176 124 93 124 93
'Johnson' 43 'Male' false 69 163 109 77 109 77
'Williams' 38 'Female' false 64 131 125 83 125 83
'Jones' 40 'Female' false 67 133 117 75 117 75
'Brown' 49 'Female' false 64 119 122 80 122 80
T now has 9 variables and 100 rows. A table variable can have multiple columns. So
although BloodPressure has two columns, it is one table variable.
Add a new variable, BMI, in the table T, that contains the body mass index for each
patient. BMI is a function of height and weight. When you calculate BMI, you can refer to
the Weight and Height variables that are in T.
T.BMI = (T.Weight0.453592)./(T.Height0.0254).^2;
The operators ./ and .^ in the calculation of BMI indicate element-wise division and
exponentiation, respectively.
Display the first five rows of the table T.
head(T,5)
ans=5×10 table
LastName Age Gender Smoker Height Weight Systolic Diastolic BloodPressure BMI
'Smith' 38 'Male' true 71 176 124 93 124 93 24.547
'Johnson' 43 'Male' false 69 163 109 77 109 77 24.071
'Williams' 38 'Female' false 64 131 125 83 125 83 22.486
'Jones' 40 'Female' false 67 133 117 75 117 75 20.831
'Brown' 49 'Female' false 64 119 122 80 122 80 20.426
Move Variable in Table
Move the table variable BMI using the movevars function, so that it is after the variable
Weight. When you specify table variables by name, use quotation marks.
T = movevars(T,'BMI','After','Weight');
head(T,5)
ans=5×10 table
LastName Age Gender Smoker Height Weight BMI Systolic Diastolic BloodPressure
Add, Delete, and Rearrange Table Variables