retime

Changes the row times of a timetable, filling in values by interpolation or another rule.

Category: Language Fundamentals > Data Types

Syntax

TT2 = retime(TT, newTimes, method)

Evaluates the timetable at newTimes using method.

TT2 = retime(TT, 'regular', method, 'TimeStep', dt)

Builds a regular time grid with step dt.

TT2 = retime(TT, 'secondly', method)

Uses a built-in time step such as 'secondly', 'minutely' or 'daily'.

Description

When the new times are denser than the old ones, the method fills in the missing values: 'linear' interpolates, 'previous' repeats the last known value and 'fillwithmissing' leaves NaN. When they are sparser, aggregation methods such as 'mean' and 'sum' combine the rows that fall within each interval.

Use synchronize to align several timetables with each other.

Input arguments

TT
Timetable.
newTimes
Datetime or duration vector.
method
Rule such as 'linear', 'previous', 'next', 'nearest', 'fillwithmissing', 'fillwithconstant', 'sum' or 'mean'.

Output arguments

TT2
Timetable on the new times, with the same variables.

Example

TT = timetable(seconds([1;2;4]), [10;20;40]);
retime(TT, seconds(1:4), 'linear')
retime(TT, seconds(1:4), 'previous')
retime(TT, seconds(1:4), 'fillwithmissing')
Output
ans = 4×1 timetable

    Time     Var1
    _____    ____

    1 sec     10 
    2 sec     20 
    3 sec     30 
    4 sec     40 
ans = 4×1 timetable

    Time     Var1
    _____    ____

    1 sec     10 
    2 sec     20 
    3 sec     20 
    4 sec     40 
ans = 4×1 timetable

    Time     Var1
    _____    ____

    1 sec     10 
    2 sec     20 
    3 sec    NaN 
    4 sec     40

See also

timetable synchronize resample interp1 timerange seconds