Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Timetable Properties

Access and modify timetable metadata properties

A timetable, TT, has properties that store metadata such as its variable names, row times, descriptions, and variable units. TT.Properties returns a summary of all of the timetable properties.

You can access a property using TT.Properties.PropName, where TT is the name of the timetable and PropName is one of the timetable properties. For example, to access the VariableDescriptions property of a timetable named Weather, use Weather.Properties.VariableDescriptions.

You can modify a property value using TT.Properties.PropName = P where TT is the name of the timetable, PropName is one of the timetable properties, and P is the desired property value. For example, to modify the VariableUnits property of a timetable named Weather, use Weather.Properties.VariableUnits = P where P is a cell array of character vectors containing the specified information.

In contrast, you can access and modify variables within a timetable using TT.VarName or TT.VarName = V, where TT is the name of the timetable, VarName is the name of the variable you want to access or modify, and V is the variable value you want.

You also can concatenate all the timetable variables into an array using TT.Variables, where TT is the name of the timetable. TT.Variables returns the same array as the TT{:,:} syntax.

Timetable Metadata

expand all

Variable names, specified as a cell array of character vectors that are nonempty and distinct. Variable names must be valid MATLAB® variable names. The number of character vectors must equal the number of variables. MATLAB removes any leading or trailing white space from the character vectors.

If valid MATLAB identifiers are not available for use as variable names, MATLAB uses a cell array of N character vectors of the form {'Var1' ... 'VarN'} where N is the number of variables. You can determine valid MATLAB variable names using the function isvarname.

The variable names are visible when viewing the timetable and when using the summary function. Furthermore, you can use the variable names within parentheses, within curly braces, or with dot indexing to access timetable data.

Example

Create a timetable.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3])
TT =

  3×3 timetable

        Time       Var1    Var2     Var3
    ___________    ____    _____    ____

    18-Dec-2015    37.3     30.1    13.4
    19-Dec-2015    39.1    30.03     6.5
    20-Dec-2015    42.3     29.9     7.3

Modify variable names using the Properties.VariableNames property.

TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'}
TT =

  3×3 timetable

        Time       Temp    Pressure    WindSpeed
    ___________    ____    ________    _________

    18-Dec-2015    37.3     30.1       13.4     
    19-Dec-2015    39.1    30.03        6.5     
    20-Dec-2015    42.3     29.9        7.3     

Create a subtable. Include all rows, but subscript on Temp and Pressure.

TT(:,{'Temp','Pressure'})
ans =

  3×2 timetable

        Time       Temp    Pressure
    ___________    ____    ________

    18-Dec-2015    37.3     30.1   
    19-Dec-2015    39.1    30.03   
    20-Dec-2015    42.3     29.9   

Extract data from TT. Use variable names within curly braces to extract the data from the variables Pressure and WindSpeed.

TT{:,{'Pressure','WindSpeed'}}
ans =

   30.1000   13.4000
   30.0300    6.5000
   29.9000    7.3000

Extract data from the variable Temp using dot indexing.

TT.Temp
ans =

   37.3000
   39.1000
   42.3000

Extract all data using the Variables property. TT.Variables is equivalent to TT{:,:}.

TT.Variables
ans =

   37.3000   30.1000   13.4000
   39.1000   30.0300    6.5000
   42.3000   29.9000    7.3000

Row times, specified as a datetime vector or duration vector. There must be a row time for every row of the timetable. However, a timetable can have row times that are duplicates, out of order, or NaT or NaN values.

The row times are visible when you view the timetable. Furthermore, you can use the row times within parentheses or curly braces to access the timetable data.

Example

Create a timetable.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3])
TT =

  3×3 timetable

        Time       Var1    Var2     Var3
    ___________    ____    _____    ____

    18-Dec-2015    37.3     30.1    13.4
    19-Dec-2015    39.1    30.03     6.5
    20-Dec-2015    42.3     29.9     7.3

Display row times using the Properties.RowTimes property.

TT.Properties.RowTimes
ans = 

  3×1 datetime array

   18-Dec-2015
   19-Dec-2015
   20-Dec-2015

Display row times by the name of the vector of row times.

TT.Time
ans = 

  3×1 datetime array

   18-Dec-2015
   19-Dec-2015
   20-Dec-2015

Create a subtable. Include all variables, but subscript on a subset of row times.

TT({'2015-12-19','2015-12-20'},:)
ans =

  2×3 timetable

        Time       Var1    Var2     Var3
    ___________    ____    _____    ____

    19-Dec-2015    39.1    30.03    6.5 
    20-Dec-2015    42.3     29.9    7.3 

Dimension names, specified as a two-element cell array of character vectors.

Example

Create a timetable. Modify the names of its dimensions using the Properties.DimensionNames property. The first dimension is the name of the vector of row times.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3]);
TT.Properties.DimensionNames = {'Date' 'WeatherData'};
TT.Properties
ans = 

  struct with fields:

             Description: ''
                UserData: []
          DimensionNames: {'Date'  'WeatherData'}
           VariableNames: {'Var1'  'Var2'  'Var3'}
    VariableDescriptions: {}
           VariableUnits: {}
                RowTimes: [3×1 datetime]

Timetable description, specified as a character vector. This description is visible when using the summary function.

Example

Create a timetable. Modify the variable names and the description of the timetable. Display a summary of the result.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3]);
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};
TT.Properties.Description = 'Weather Data from December 2015';
summary(TT)
Description:  Weather Data from December 2015

RowTimes:

    Time: 3×1 datetime
        Values:

            Min          18-Dec-2015 
            Median       19-Dec-2015 
            Max          20-Dec-2015 
            TimeStep     24:00:00    

Variables:

    Temp: 3×1 double

        Values:

            Min       37.3  
            Median    39.1  
            Max       42.3  

    Pressure: 3×1 double

        Values:

            Min        29.9     
            Median    30.03     
            Max        30.1     

    WindSpeed: 3×1 double

        Values:

            Min        6.5       
            Median     7.3       
            Max       13.4       

Variable descriptions, specified as a cell array of character vectors. This property can be an empty cell array, which is the default. If the cell array is not empty, the number of character vectors must equal the number of variables. You can specify an individual empty character vector within the cell array for a variable that does not have a description.

The variable descriptions are visible when using the summary function.

Example

Create a timetable. Modify the variable names and descriptions. Display a summary of the result.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3]);
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};
TT.Properties.VariableDescriptions = {'Temperature (external)',...
                                      'Pressure in Hg',...
                                      'Wind speed at sensor 123'};
summary(TT)
RowTimes:

    Time: 3×1 datetime
        Values:

            Min          18-Dec-2015 
            Median       19-Dec-2015 
            Max          20-Dec-2015 
            TimeStep     24:00:00    

Variables:

    Temp: 3×1 double

        Description:  Temperature (external)
        Values:

            Min       37.3  
            Median    39.1  
            Max       42.3  

    Pressure: 3×1 double

        Description:  Pressure in Hg
        Values:

            Min        29.9     
            Median    30.03     
            Max        30.1     

    WindSpeed: 3×1 double

        Description:  Wind speed at sensor 123
        Values:

            Min        6.5       
            Median     7.3       
            Max       13.4       

Variable units, specified as a cell array of character vectors. This property can be an empty cell array, which is the default. If the cell array is not empty, the number of character vectors must equal the number of variables. You can specify an individual empty character vector within the cell array for a variable that does not have units.

The variable units are visible when using the summary function.

Example

Create a timetable. Modify the variable names and units. Display a summary of the result.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3]);
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};
TT.Properties.VariableUnits = {'degrees F' 'mm Hg' 'mph'};
summary(TT)
RowTimes:

    Time: 3×1 datetime
        Values:

            Min          18-Dec-2015 
            Median       19-Dec-2015 
            Max          20-Dec-2015 
            TimeStep     24:00:00    

Variables:

    Temp: 3×1 double

        Units:  degrees F
        Values:

            Min       37.3  
            Median    39.1  
            Max       42.3  

    Pressure: 3×1 double

        Units:  mm Hg
        Values:

            Min        29.9     
            Median    30.03     
            Max        30.1     

    WindSpeed: 3×1 double

        Units:  mph
        Values:

            Min        6.5       
            Median     7.3       
            Max       13.4       

Additional timetable information, specified as a variable containing information in any data type.

Example

Create a timetable. Modify the variable names. Attach an anonymous function as a piece of user data that is associated with the timetable.

TT = timetable(datetime({'2015-12-18';'2015-12-19';'2015-12-20'}),...
               [37.3;39.1;42.3],[30.1;30.03;29.9],[13.4;6.5;7.3]);
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};
Fahrenheit2Celsius = @(x) (5.0/9.0).*(x - 32);
TT.Properties.UserData = Fahrenheit2Celsius;
TT.Properties
ans = 

  struct with fields:

             Description: ''
                UserData: @(x)(5.0/9.0).*(x-32)
          DimensionNames: {'Time'  'Variables'}
           VariableNames: {'Temp'  'Pressure'  'WindSpeed'}
    VariableDescriptions: {}
           VariableUnits: {}
                RowTimes: [3×1 datetime]

Introduced in R2016b

Was this topic helpful?