This example shows how to access and modify table properties for variable units, descriptions and names. You also can edit these property values using the Variables Editor.
Load the sample patients data and create a table.
load patients
BloodPressure = [Systolic Diastolic];
T = table(Gender,Age,Height,Weight,Smoker,BloodPressure);Display the first five rows of the table, T.
T(1:5,:)
ans=5×6 table
Gender Age Height Weight Smoker BloodPressure
__________ ___ ______ ______ ______ _____________
{'Male' } 38 71 176 true 124 93
{'Male' } 43 69 163 false 109 77
{'Female'} 38 64 131 false 125 83
{'Female'} 40 67 133 false 117 75
{'Female'} 49 64 119 false 122 80
T has 100 rows and 6 variables.
Specify units for each variable in the table by modifying the table property, VariableUnits. Specify the variable units as a cell array of character vectors.
T.Properties.VariableUnits = {'' 'Yrs' 'In' 'Lbs' '' ''};An individual empty character vector within the cell array indicates that the corresponding variable does not have units.
Add a variable description for the variable, BloodPressure. Assign a single character vector to the element of the cell array containing the description for BloodPressure.
T.Properties.VariableDescriptions{'BloodPressure'} = 'Systolic/Diastolic';You can use the variable name, 'BloodPressure', or the numeric index of the variable, 6, to index into the cell array of character vectors containing the variable descriptions.
View the data type, description, units, and other descriptive statistics for each variable by using summary to summarize the table.
summary(T)
Variables:
Gender: 100x1 cell array of character vectors
Age: 100x1 double
Properties:
Units: Yrs
Values:
Min 25
Median 39
Max 50
Height: 100x1 double
Properties:
Units: In
Values:
Min 60
Median 67
Max 72
Weight: 100x1 double
Properties:
Units: Lbs
Values:
Min 111
Median 142.5
Max 202
Smoker: 100x1 logical
Values:
True 34
False 66
BloodPressure: 100x2 double
Properties:
Description: Systolic/Diastolic
Values:
Column 1 Column 2
________ ________
Min 109 68
Median 122 81.5
Max 138 99
The BloodPressure variable has a description and the Age, Height, Weight, and BloodPressure variables have units.
Change the variable name for the first variable from Gender to Sex.
T.Properties.VariableNames{'Gender'} = 'Sex';Display the first five rows of the table, T.
T(1:5,:)
ans=5×6 table
Sex Age Height Weight Smoker BloodPressure
__________ ___ ______ ______ ______ _____________
{'Male' } 38 71 176 true 124 93
{'Male' } 43 69 163 false 109 77
{'Female'} 38 64 131 false 125 83
{'Female'} 40 67 133 false 117 75
{'Female'} 49 64 119 false 122 80
In addition to properties for variable units, descriptions and names, there are table properties for row and dimension names, a table description, and user data.
array2table | cell2table | readtable | struct2table | summary | table