MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

T = sortrows(T,'RowNames');


T(1:5,:)


ans=5×8 table
Gender Smoker Height Weight ID BMI Systolic Diastolic




Adams 'Female' false 66 137 8235 22.112 127 83
Alexander 'Male' true 69 171 1300 25.252 128 99
Allen 'Female' false 63 143 7432 25.331 113 80
Anderson 'Female' false 68 128 1577 19.462 114 77
Bailey 'Female' false 68 130 2239 19.766 113 81


Create a BloodPressure variable to hold blood pressure readings in a 100-by-2 table
variable.


T.BloodPressure = [T.Systolic T.Diastolic];


Delete Systolic and Diastolic from the table since they are redundant.


T.Systolic = [];
T.Diastolic = [];


T(1:5,:)


ans=5×7 table
Gender Smoker Height Weight ID BMI BloodPressure




Adams 'Female' false 66 137 8235 22.112 127 83
Alexander 'Male' true 69 171 1300 25.252 128 99
Allen 'Female' false 63 143 7432 25.331 113 80
Anderson 'Female' false 68 128 1577 19.462 114 77
Bailey 'Female' false 68 130 2239 19.766 113 81


To put ID as the first column, reorder the table variables by position.


T = T(:,[5 1:4 6 7]);


T(1:5,:)


ans=5×7 table
ID Gender Smoker Height Weight BMI BloodPressure


Create and Work with Tables
Free download pdf