Retime Timetable
Description
The Retime Timetable task lets you interactively change the row times of a timetable and then resample or aggregate the data in its variables. The task 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 monthly data).
Remove rows that have duplicate row times.
Make an irregular timetable into a regular one by specifying a uniform time step or sample rate.
More
Related Functions
Retime Timetable generates code that uses the retime
function.
Open the Task
To add the Retime Timetable task to a live script in the MATLAB Editor:
On the Live Editor tab, select Task > Retime Timetable.
In a code block in the script, type a relevant keyword, such as
retime
,timetable
,upsample
, ordownsample
. Select Retime Timetable from the suggested command completions. For some keywords, the task automatically updates one or more corresponding parameters.
Examples
Resample and Aggregate Timetable Data Using Live Editor Task
The example shows how to resample and aggregate data in a timetable by using the Retime Timetable Live Editor task. You also can apply different rules for adjusting timetable variables in different ways.
Resample Data
Create a timetable using column vectors of data. The row times are between 10 and 50 milliseconds.
Intensity = [100 98.7 95.2 101.4 99.1]'; Time = milliseconds([11 20 34 40.3 49.9])'; TT1 = timetable(Time,Intensity)
TT1=5×1 timetable
Time Intensity
__________ _________
0.011 sec 100
0.02 sec 98.7
0.034 sec 95.2
0.0403 sec 101.4
0.0499 sec 99.1
Add the Retime Timetable task to your live script. Resample the data in TT
.
To specify a sample rate of 100 Hz, use the
Selection method
menus.To adjust the data in the
Intensity
variable by using linear interpolation, use theGeneral rule
menu.
newTimetable=5×1 timetable
Time Intensity
________ _________
0.01 sec 100.14
0.02 sec 98.7
0.03 sec 96.2
0.04 sec 101.1
0.05 sec 99.076
Aggregate Data
Load a second timetable from the bostonTT
MAT-file. This timetable has temperature, wind speed, and rainfall measurements for the city of Boston. The measurements are approximately six hours apart but are irregular.
load bostonTT
Boston
Boston=6×3 timetable
Time Temp WindSpeed Rain
___________________ ____ _________ ____
2016-06-09 06:03:00 59.5 0.1 0.05
2016-06-09 12:00:23 63 2.3 0.08
2016-06-09 18:02:57 61.7 3.1 0.13
2016-06-10 06:01:47 55.4 5.7 0.15
2016-06-10 12:06:00 62.3 2.6 0.87
2016-06-10 18:02:57 58.8 6.2 0.33
Add a second instance of the Retime Timetable task to your live script. Aggregate the data into daily time bins.
To specify a time step of one day, use the
Selection method
menus.To calculate means of the timetable variables, use the
General rule
menu.To specify a different rule for the
Rain
variable, use theExceptions
menus. Add an exception to interpolate rainfall measurements at the beginning of each day.
newTimetable2=2×3 timetable
Time Temp WindSpeed Rain
___________________ ______ _________ ________
2016-06-09 00:00:00 61.4 1.8333 0.019529
2016-06-10 00:00:00 58.833 4.8333 0.13993
Related Examples
Parameters
Input timetable
— Name of timetable
drop-down list item
Specify the name from a list of all the nonempty timetables that are in the workspace.
Selection method
— Method for specifying row times
drop-down list item
Specify the method for calculating new row times of the 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 ofdatetime
orduration
values. The times in the vector replace the row times of the timetable. The times need not be regularly spaced.
General rule
— Rule for adjusting data values
drop-down list item
Specify the rule for adjusting data values in the variables of the timetable. The rule applies to all variables 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.
Exceptions
— Different rule or rules for adjusting specified variables
drop-down list item
Click the Add button. Then specify a timetable variable from the drop-down list of variable names that appears.
To adjust the data in the specified variable, select a rule from the drop-down list of rules to the right of the variable name. 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 variable names and rules appear below the previous exception.
Version History
Introduced in R2020aR2024b: Specify custom function as local function or function handle
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:
Select
Custom function
.Select
Local function
from the next menu.If you want to add a new local function to the script, click New. The task generates template code for a custom aggregation function within the live script. To customize this code, edit it in the live script.
Select the name of the local function from the
select
menu.
To specify a function handle:
Select
Custom function
.Select
Function handle
from the next menu.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.
R2022a: Live Editor task does not run automatically if inputs have more than 1 million elements
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.
R2020b: Retime Timetable Live Editor Task: Use linear interpolation as default general rule for adjusting data
In R2020b, linear interpolation is the default general rule for adjusting data in the Retime Timetable live editor task. In previous releases, the default general rule was to fill gaps in the output timetable with missing values.
However, even in R2020b the default rule reverts to filling gaps with missing values if either of these conditions is met:
The row times of the input timetable are not sorted.
The input timetable has at least one variable whose data type is not numeric,
datetime
, orduration
.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)