Main Content

Synchronize Timetables

Retime and combine timetables to new time vector in the Live Editor

Since R2020a

Description

The Synchronize Timetables task lets you interactively collect variables from all input timetables, synchronize them to a common time vector, and return the result as a single timetable. The effect is similar to a horizontal concatenation, though the input timetables can have different row times. The task also automatically generates MATLAB® code for your live script.

Using this task, you can:

  • Interpolate data values at new row times.

  • Aggregate data into time bins (for example, to create a timetable containing quarterly means from timetables containing monthly data).

  • Remove rows that have duplicate row times.

  • Make the output a regular one by specifying a uniform time step or sample rate.

Related Functions

Synchronize Timetables generates code that uses the synchronize function.

Synchronize Timetables task in Live Editor

Open the Task

To add the Synchronize Timetables task to a live script in the MATLAB Editor:

  • On the Live Editor tab, select Task > Synchronize Timetables.

  • In a code block in the script, type a relevant keyword, such as synchronize, timetable, upsample, or downsample. Select Synchronize Timetables from the suggested command completions. For some keywords, the task automatically updates one or more corresponding parameters.

Examples

expand all

This example shows how to use the Synchronize Timetables Live Editor task to synchronize data in input timetables.

First, load two small timetables from the firstTT MAT-file. TT1 contains temperature measurements, and TT2 contains humidity measurements.

load firstTT
TT1
TT1=3×1 timetable
            Time            Temp
    ____________________    ____

    06-Jun-2016 15:00:00    79.7
    06-Jun-2016 16:00:00    76.3
    06-Jun-2016 17:00:00    74.9

TT2
TT2=4×1 timetable
            Time            Humidity
    ____________________    ________

    06-Jun-2016 14:35:48      49.7  
    06-Jun-2016 15:35:48      52.2  
    06-Jun-2016 16:35:48      56.7  
    06-Jun-2016 17:35:48        60  

Add the Synchronize Timetables task to your live script.

  • To specify new row times that are the union of the row times from TT1 and TT2, use the Selection method menus.

  • To adjust data by filling gaps in the output timetable variables, use the General rule menu. Select Fill with missing as the rule. The task fills gaps with the missing value that is appropriate for the data type of each timetable variable. For numeric variables, the missing value is NaN.

Live Task
newTimetable=7×2 timetable
            Time            Temp    Humidity
    ____________________    ____    ________

    06-Jun-2016 14:35:48     NaN      49.7  
    06-Jun-2016 15:00:00    79.7       NaN  
    06-Jun-2016 15:35:48     NaN      52.2  
    06-Jun-2016 16:00:00    76.3       NaN  
    06-Jun-2016 16:35:48     NaN      56.7  
    06-Jun-2016 17:00:00    74.9       NaN  
    06-Jun-2016 17:35:48     NaN        60  

You can fill gaps with interpolated values instead of NaNs. Specify linear interpolation as the general rule.

Live Task
newTimetable2=7×2 timetable
            Time             Temp     Humidity
    ____________________    ______    ________

    06-Jun-2016 14:35:48    81.071       49.7 
    06-Jun-2016 15:00:00      79.7     50.708 
    06-Jun-2016 15:35:48    77.671       52.2 
    06-Jun-2016 16:00:00      76.3     54.014 
    06-Jun-2016 16:35:48    75.464       56.7 
    06-Jun-2016 17:00:00      74.9      58.03 
    06-Jun-2016 17:35:48    74.064         60 

Synchronize to a regular hourly time vector instead of the union of row times.

Live Task
newTimetable3=5×2 timetable
            Time            Temp    Humidity
    ____________________    ____    ________

    06-Jun-2016 14:00:00    83.1     48.208 
    06-Jun-2016 15:00:00    79.7     50.708 
    06-Jun-2016 16:00:00    76.3     54.014 
    06-Jun-2016 17:00:00    74.9      58.03 
    06-Jun-2016 18:00:00    73.5      61.33 

Related Examples

Parameters

expand all

Specify the names of two or more input timetables from lists of all the nonempty timetables that are in the workspace.

You can specify the names of two timetables using the two drop-down lists initially provided. To specify more timetables, click the + button to the right of a drop-down list. You can add an unlimited number of timetables.

Specify the method for calculating new row times of the output timetable.

  • Times from timetables — Method for extracting row times from one or more input timetables. For example, you can use the union of the row times from all timetables, or the intersection, or the row times from the last timetable.

  • Time step — Length of time between consecutive regularly spaced row times.

  • Sample rate — Sample rate or frequency for regularly spaced row times.

  • Times from workspace — Workspace variable that is a vector of datetime or duration values. The times in the vector become the row times of the output timetable. The times need not be regularly spaced.

Specify the rule for adjusting data values in the variables of the timetables. The rule applies to all variables from all input timetables unless exceptions are specified. You can resample or aggregate data values to:

  • Fill gaps with missing data indicators or a constant value.

  • Interpolate data values to the new row times. For example, resample data measured at 100 Hz to 200 Hz.

  • Aggregate data into time bins. For example, calculate a daily mean from data values measured at every hour.

Click the Add button. Then specify a timetable variable from the drop-down lists of timetable names and variable names that appear. Select an input timetable from the first list, then one of its variables from the second list.

  • To adjust the data in the specified variable, select a rule from the third drop-down list, to the right of the list of variables. The rule for the exception can differ from the general rule.

  • To specify exceptions for other timetable variables, click the + button to the right of the first exception. New drop-down lists of timetable names, variable names, and rules appear below the previous exception.

Version History

Introduced in R2020a

expand all

See Also

Functions

Live Editor Tasks

Apps