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

Access and Modify 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.

Properties

collapse 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 = 

       Time       Var1    Var2     Var3
    __________    ____    _____    ____

    2015-12-18    37.3     30.1    13.4
    2015-12-19    39.1    30.03     6.5
    2015-12-20    42.3     29.9     7.3
%% Modify variable names
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'}
TT = 

       Time       Temp    Pressure    WindSpeed
    __________    ____    ________    _________

    2015-12-18    37.3     30.1       13.4     
    2015-12-19    39.1    30.03        6.5     
    2015-12-20    42.3     29.9        7.3     
%% Create a subtable
%
% Use variable names within parentheses to create a subtable.
% Include all the rows, but only the variables Temp and Pressure.
TT(:,{'Temp','Pressure'})
ans = 

       Time       Temp    Pressure
    __________    ____    ________

    2015-12-18    37.3     30.1   
    2015-12-19    39.1    30.03   
    2015-12-20    42.3     29.9   
%% Extract data from the table
%
% 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
% Use variable names with dot indexing to extract 
% all the data from the variable Temp.
TT.Temp
ans =

   37.3000
   39.1000
   42.3000
% Use TT.Variables to extract all
% the data from all the variables.
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]);

% Display row times
TT.Properties.RowTimes
ans = 

   2015-12-18
   2015-12-19
   2015-12-20
% Display row times
TT.Time
ans = 

   2015-12-18
   2015-12-19
   2015-12-20
% Access rows by row times
TT({'2015-12-19','2015-12-20'},:)
ans = 

       Time       Temp    Pressure    WindSpeed
    __________    ____    ________    _________

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

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

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]);

% Add dimension names
TT.Properties.DimensionNames = {'Date' 'WeatherData'};

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

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]);

%% Modify variable names
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};

% Add a table description
TT.Properties.Description = 'Weather Data from December 2015';

% View the summary
format compact
summary(TT)
Description:  Weather Data from December 2015
Variables:
    Temp: 3x1 double
        Values:
            min       37.3  
            median    39.1  
            max       42.3  
    Pressure: 3x1 double
        Values:
            min        29.9     
            median    30.03     
            max        30.1     
    WindSpeed: 3x1 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
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]);

%% Modify variable names
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};

% Add variable descriptions
TT.Properties.VariableDescriptions = {'Temperature (external)',...
                                      'Pressure in Hg',...
                                      'Wind speed at sensor 123'};

% View the summary
format compact
summary(TT)
Variables:
    Temp: 3x1 double
        Description:  Temperature (external)
        Values:
            min       37.3  
            median    39.1  
            max       42.3  
    Pressure: 3x1 double
        Description:  Pressure in Hg
        Values:
            min        29.9     
            median    30.03     
            max        30.1     
    WindSpeed: 3x1 double
        Description:  Wind speed at sensor 123
        Values:
            min        6.5       
            median     7.3       
            max       13.4       
% Remove all the variable descriptions
TT.Properties.VariableDescriptions = {};

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
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]);

%% Modify variable names
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};

% Add variable units
TT.Properties.VariableUnits = {'degrees F' 'mm Hg' 'mph'};

% View the summary
format compact
summary(TT)
Variables:
    Temp: 3x1 double
        Units:  degrees F
        Values:
            min       37.3  
            median    39.1  
            max       42.3  
    Pressure: 3x1 double
        Units:  mm Hg
        Values:
            min        29.9     
            median    30.03     
            max        30.1     
    WindSpeed: 3x1 double
        Units:  mph
        Values:
            min        6.5       
            median     7.3       
            max       13.4         
% Remove all the variable units
TT.Properties.VariableUnits = {};

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

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]);

%% Modify variable names
TT.Properties.VariableNames = {'Temp' 'Pressure' 'WindSpeed'};

% Add an anonymous function to the table metadata
Fahrenheit2Celsius = @(x) (5.0/9.0).*(x - 32);
TT.Properties.UserData = Fahrenheit2Celsius;

Was this topic helpful?