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

Create timetable from workspace variables

The timetable function creates a timetable. For more information on creating and using timetables, see Timetables.

Syntax

  • TT = timetable(rowTimes,var1,...,varN)
    example
  • TT = timetable(var1,...,varN,'RowTimes',rowTimes)
    example
  • TT = timetable(___,'VariableNames',{varName1,...,varNameN})
    example

Description

example

TT = timetable(rowTimes,var1,...,varN) creates a timetable from the input data variables var1,...,varN and the time vector rowTimes. The data variables can be different sizes and data types as long as they have the same number of rows. rowTimes must be a datetime or duration vector, also with the same number of rows.

To create a timetable from a table or an array, use the table2timetable or array2timetable function.

example

TT = timetable(var1,...,varN,'RowTimes',rowTimes) creates a timetable from the input data variables var1,...,varN and the time vector rowTimes.

example

TT = timetable(___,'VariableNames',{varName1,...,varNameN}) creates a timetable and assigns the variables the names varName1,...,varNameN. The variable names must be unique, valid MATLAB® identifiers in a cell array. You can use this syntax with any of the input arguments of the previous syntaxes.

Examples

collapse all

Create a timetable from workspace variables that contain times as well as temperature, pressure, and wind speed and direction measurements. The values in Time become the row times of the timetable. All the other workspace variables become the timetable variables.

Time = datetime({'2015-12-18 08:03:05';'2015-12-18 10:03:17';'2015-12-18 12:03:13'});
Temp = [37.3;39.1;42.3];
Pressure = [30.1;30.03;29.9];
WindSpeed = [13.4;6.5;7.3];
WindDirection = categorical({'NW';'N';'NW'});
TT = timetable(Time,Temp,Pressure,WindSpeed,WindDirection)
TT = 

            Time            Temp    Pressure    WindSpeed    WindDirection
    ____________________    ____    ________    _________    _____________

    18-Dec-2015 08:03:05    37.3     30.1       13.4         NW           
    18-Dec-2015 10:03:17    39.1    30.03        6.5         N            
    18-Dec-2015 12:03:13    42.3     29.9        7.3         NW           

Create a timetable from workspace variables that contain dates as well as temperature, pressure, and precipitation readings, and the durations of storms on those dates. Specify Date as the vector of row times.

Date = datetime({'2015-12-18';'2015-12-18';'2015-12-18'});
Temp = [37.3;39.1;42.3];
Pressure = [29.4;29.6;30.0];
Precip = [0.1;0.9;0.0];
StormDuration = [hours(1);hours(2);NaN];
TT = timetable(Temp,Pressure,Precip,StormDuration,'RowTimes',Date)
TT = 

        Time       Temp    Pressure    Precip    StormDuration
    ___________    ____    ________    ______    _____________

    18-Dec-2015    37.3    29.4        0.1         1 hr       
    18-Dec-2015    39.1    29.6        0.9         2 hr       
    18-Dec-2015    42.3      30          0       NaN hr       

Create a timetable and specify the names of the timetable variables. The vector of row times is a duration vector, whose units are seconds.

Time = seconds(1:5)';
TT = timetable(Time,[98;97.5;97.9;98.1;97.9],[120;111;119;117;116],...
               'VariableNames',{'Reading1','Reading2'})
TT = 

     Time    Reading1    Reading2
    _____    ________    ________

    1 sec      98        120     
    2 sec    97.5        111     
    3 sec    97.9        119     
    4 sec    98.1        117     
    5 sec    97.9        116     

Related Examples

Input Arguments

collapse all

Input variables, specified as arrays with the same number of rows. The input variables can be of different sizes and different data types, as long as they have the same number of rows.

Common input variables are numeric arrays, logical arrays, string arrays, structure arrays, or cell arrays.

Input variables also can be objects that are arrays. Such an array must support indexing of the form var(index1,...,indexN), where index1 is a numeric or logical vector that corresponds to rows of the variable var. In addition, the array must implement both a vertcat method and a size method with a dim argument.

Times associated with rows of a timetable, specified as a datetime vector or a duration vector. Each time value in rowTimes labels a row in the output timetable, TT. The time values in rowTimes do not need to be unique, sorted, or regular.

Output Arguments

collapse all

Output timetable. The timetable can store metadata such as descriptions, variable units, variable names, and row times. For more information, see Timetable Properties.

Unless you specify the timetable variable names using the VariableNames name-value pair argument, the timetable function generates the variable names automatically. If an input argument is a variable in the current workspace, timetable uses that variable name as the timetable variable name. Otherwise, it uses a name consisting of Var followed by an integer, such as Var2.

Introduced in R2016b

Was this topic helpful?