Documentation Center

  • Trial Software
  • Product Updates

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.

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 = 

     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.

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 strings.

T.Properties.VariableUnits = {'' 'Yrs' 'In' 'Lbs' '' ''};

An individual empty string within the cell array indicates that the corresponding variable does not have units.

Add a Variable Description for a Single Variable

Add a variable description for the variable, BloodPressure. Assign a single string to the element of the cell array of strings 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 strings containing the variable descriptions.

Summarize the Table

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 string

    Age: 100x1 double
        Units:  Yrs
        Values:

            min       25   
            median    39   
            max       50   

    Height: 100x1 double
        Units:  In
        Values:

            min       60      
            median    67      
            max       72      

    Weight: 100x1 double
        Units:  Lbs
        Values:

            min         111   
            median    142.5   
            max         202   

    Smoker: 100x1 logical
        Values:

            true     34      
            false    66      

    BloodPressure: 100x2 double
        Description:  Systolic/Diastolic
        Values:
                      BloodPressure_1    BloodPressure_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 a Variable Name

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 = 

      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

| | | | | |

Related Examples

Was this topic helpful?