timeseries2timetable

Convert timeseries objects to timetable

Description

example

TT = timeseries2timetable(ts) converts the timeseries array ts to a timetable.

• If ts is a timeseries object, then TT is a timetable with one variable.

• If ts is an array of timeseries objects, then TT is a timetable with as many variables as there are timeseries objects in ts. All of the timeseries objects in ts must have the same sample times.

example

TT = timeseries2timetable(ts1,...,tsN) converts the timeseries objects ts1,...,tsN to a timetable. The number of variables in TT equals the number of inputs. All of the timeseries objects ts1,...,tsN must have the same sample times.

Examples

collapse all

Create a timeseries object that has five random numbers, sampled at 10 second intervals.

ts = timeseries(rand(5,1),[0 10 20 30 40])
timeseries

Common Properties:
Name: 'unnamed'
Time: [5x1 double]
Data: [5x1 double]

Display the times and data in ts.

ts.Time
ans = 5×1

0
10
20
30
40

ts.Data
ans = 5×1

0.8147
0.9058
0.1270
0.9134
0.6324

Convert ts to a timetable.

TT = timeseries2timetable(ts)
TT=5×1 timetable
Time      Data
______    _______

0 sec     0.81472
10 sec    0.90579
20 sec    0.12699
30 sec    0.91338
40 sec    0.63236

Create an array of timeseries objects. Use the same vector of sample times but give the time series different names. Create different arrays of data values by using the rand function.

ts1 = timeseries(rand(5,1),[0 10 20 30 40],"Name","Series_1");
ts2 = timeseries(rand(5,1),[0 10 20 30 40],"Name","Series_2");
ts3 = timeseries(rand(5,1),[0 10 20 30 40],"Name","Series_3");
ts = [ts1 ts2 ts3]
1x3 timeseries array with properties:

Events
Name
UserData
Data
DataInfo
Time
TimeInfo
Quality
QualityInfo
IsTimeFirst
TreatNaNasMissing
Length

Combine data from all the timeseries objects into one timetable. Each time series in the array contributes a variable to the timetable.

TT = timeseries2timetable(ts)
TT=5×3 timetable
Time     Series_1    Series_2    Series_3
______    ________    ________    ________

0 sec     0.81472     0.09754     0.15761
10 sec    0.90579      0.2785     0.97059
20 sec    0.12699     0.54688     0.95717
30 sec    0.91338     0.95751     0.48538
40 sec    0.63236     0.96489     0.80028

Convert multiple inputs to a timetable.

ts1 = timeseries(rand(5,1),[0 10 20 30 40],"Name","Series_1");
ts2 = timeseries(rand(5,1),[0 10 20 30 40],"Name","Series_2");
ts3 = timeseries(rand(5,1),[0 10 20 30 40],"Name","Series_3");
TT = timeseries2timetable(ts1,ts2,ts3)
TT=5×3 timetable
Time     Series_1    Series_2    Series_3
______    ________    ________    ________

0 sec     0.81472     0.09754     0.15761
10 sec    0.90579      0.2785     0.97059
20 sec    0.12699     0.54688     0.95717
30 sec    0.91338     0.95751     0.48538
40 sec    0.63236     0.96489     0.80028

Input Arguments

collapse all

Input time series, specified as an array of timeseries objects.

This function uses some of the properties of ts to either assign data or set properties in the timetable. For each timeseries property, the table describes the result in the output timetable.

Input timeseries Property

Result in Output Timetable

Name

Specifies name of the corresponding timetable variable.

If Name is 'unnamed' (the default value), then the corresponding variable name is 'Data' (or 'Data_1', 'Data_2', and so on, when multiple time series have 'unnamed' as their names).

Data

Specifies data assigned to the corresponding timetable variable.

DataInfo.Units

Sets the VariableUnits property for the corresponding timetable variable.

DataInfo.Interpolation

Sets the VariableContinuity property for the corresponding timetable variable.

Time

Converts sample times to row times of timetable. The vector of row times is either a duration or datetime vector, depending on the information in the Time and TimeInfo properties of the input.

TimeInfo.Units

Specifies units for row times. If the vector of timetable row times is a duration vector, then TimeInfo.Units also determines its format.

TimeInfo.Format

Sets format for row times.

TimeInfo.StartDate

Sets the StartTime property of the timetable.

TimeInfo.Increment

Sets the TimeStep property.

TimeInfo.Start

Calculates offset from TimeInfo.StartDate to specify StartTime property of the timetable.

IsTimeFirst

Determines if data needs to be reoriented.

UserData

Assigns data to the UserData property of the timetable.

Events

Warns.

Quality

Warns.

QualityInfo

Warns if timeseries object has a Quality property.

Compatibility Considerations

expand all

Behavior changed in R2021b

Introduced in R2021b