Main Content

Modify Units, Descriptions, and Table Variable Names

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 Sample Data

Load the sample patients data and create a table.

loadpatients血压= [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桌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

Thas 100 rows and 6 variables.

Add Variable Units

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''在''Lbs'''''};

单元格数组中的单个空字符向量表示相应的变量没有单位。

为单个变量添加变量描述

Add a variable description for the variable,血压. Assign a single character vector to the element of the cell array containing the description for血压.

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.

Summarize the Table

查看每个变量的数据类型,描述,单位和其他描述性统计信息summaryto 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血压variable has a description and theAge,高度,Weight, and血压variables have units.

Change a Variable Name

Change the variable name for the first variable fromGendertoSex.

t.properties.variablenames {'Gender'} ='Sex';

Display the first five rows of the table,T.

t(1:5,:)
ans=5×6桌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.

See Also

|||||

相关话题