Synchronize Timetables - Retime and combine timetables to new time vector in the Live Editor - MATLAB (original) (raw)

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

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:

Synchronize Timetables generates code that uses thesynchronize function.

Synchronize Timetables task in Live Editor

Open the Task

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

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.

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

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 

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.

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:

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.

Version History

Introduced in R2020a

expand all

When you select the Custom function option for the General rule method, you can either select a locally defined function or specify a function handle.

To select a local function:

  1. Select Custom function.
  2. Select Local function from the next menu.
  3. If you want to add a new local function to the script, clickNew. The task generates template code for a custom aggregation function within the live script. To customize this code, edit it in the live script.
  4. Select the name of the local function from the select menu.

To specify a function handle:

  1. Select Custom function.
  2. Select Function handle from the next menu.
  3. Specify a function handle in the text box.
    You can specify a handle to a MATLAB function or write an anonymous function in the text box. For example, to specify mean as the function, type @mean in the text box.

This Live Editor task does not run automatically if the inputs have more than 1 million elements. In previous releases, the task always ran automatically for inputs of any size. If the inputs have a large number of elements, then the code generated by this task can take a noticeable amount of time to run (more than a few seconds).

When a task does not run automatically, the Autorun indicator is disabled. You can either run the task manually when needed or choose to enable the task to run automatically.

Starting in R2021b, the Synchronize Timetables Live Editor task can synchronize an unlimited number of timetables. In previous releases, the task could synchronize no more than five timetables.