Function Reference: timeseries2timetable

datatypes: TT = timeseries2timetable (ts)

datatypes: TT = timeseries2timetable (ts1, …, tsN)

datatypes: TT = timeseries2timetable (tc)

Convert time series to a timetable.

TT = timeseries2timetable (ts) returns a timetable with a variable for each series in the timeseries array ts, and TT = timeseries2timetable (ts1, …, tsN) one for each of the series ts1 to tsN, which must then each be a single series. A tscollection tc may stand for any of them and gives a variable for each of its members, in order; MATLAB accepts timeseries alone.

Every series must have samples, and all the same times, in the same units, with the same TimeInfo.StartDate; convert series on other times one by one and combine the timetables with synchronize.

The row times are the time vector: a duration array for series without a start date, displayed in the units of the series (seconds and finer units in seconds, weeks in days), and a datetime array from the start date otherwise, in the format TimeInfo.Format gives, or 'dd-MMM-uuuu HH:mm:ss' when it is empty. MATLAB copies TimeInfo.Format, a datestr format, as it is and fails; here it is translated to the datetime format that writes the same text, but for an hour on a 12-hour clock, which datestr pads with a space and a datetime writes without padding.

Each variable is named after its series, Data for a series with no name, made unique with the suffixes _1, _2, … in order. A name reserved in a timetable, Properties, Time or Variables, takes a suffix too, with a warning; MATLAB raises for the last two. The data are laid with time along the first dimension, so data whose time runs along its last dimension is permuted; a series whose samples then need more than two dimensions is refused, since a timetable here holds two-dimensional variables only, where MATLAB gives a variable of more.

DataInfo.Units becomes VariableUnits, and the interpolation method VariableContinuity: 'linear' is 'continuous' and 'zoh' is 'step'; a series with an interpolation function is refused. Properties.UserData is the UserData of the first series that has any.

The events of the series become the Properties.Events of the timetable: an eventtable of their times, with their names as EventLabels and, when any event has some, their EventData as a variable; an event held by several series appears once. MATLAB drops the events, with a warning. Quality codes are dropped, with a warning, as in MATLAB.

See also: timeseries, tscollection, timetable, eventtable

Source Code: timeseries2timetable

Each series becomes a variable of a timetable. Without a start date the row times are durations, in the units of the series.

 temp = timeseries ([12.1; 14.5; 13.2], [0; 30; 60], 'Name', 'temp');
 temp.TimeInfo.Units = 'minutes';
 temp.DataInfo.Units = 'degC';
 wind = timeseries ([3; 5; 4], [0; 30; 60], 'Name', 'wind');
 wind.TimeInfo.Units = 'minutes';
 TT = timeseries2timetable (temp, wind)
TT =
  3x2 timetable

     Time     temp    wind    
    ______    ____    ____    

    0 min     12.1       3    
    30 min    14.5       5    
    60 min    13.2       4
 TT.Properties.VariableUnits
ans =
  1x2 cell array

    {'degC'}    {0x0 char}

A dated series gives datetime row times, and its events become the timetable's event table; MATLAB drops the events.

 ts = timeseries ([3; 5; 4], {'01-Mar-2024', '02-Mar-2024', ...
                              '03-Mar-2024'}, 'Name', 'level');
 ts = addevent (ts, 'inspection', 1);
 TT = timeseries2timetable (ts);
 TT.Properties.RowTimes
ans =
  3x1 datetime array

    01-Mar-2024 00:00:00    
    02-Mar-2024 00:00:00    
    03-Mar-2024 00:00:00
 TT.Properties.Events
ans =
  1x1 eventtable

            Time             EventLabels      
    ____________________    ______________    

    02-Mar-2024 00:00:00    {'inspection'}

A collection gives a variable per member.

 tc = tscollection ({timeseries([1; 2], [0; 1], 'Name', 'a'), ...
                     timeseries([3; 4], [0; 1], 'Name', 'b')});
 timeseries2timetable (tc)
ans =
  2x2 timetable

    Time     a    b    
    _____    _    _    

    0 sec    1    3    
    1 sec    2    4