Retime and Synchronize Timetable Variables Using
Different Methods
This example shows how to fill in gaps in timetable variables, using different methods for
different variables. You can specify whether each timetable variable contains continuous
or discrete data using the VariableContinuity property of the timetable. When you
resample the timetable using the retime function, retime either interpolates, fills in
with previous values, or fills in with missing data indicators, depending on the values in
the VariableContinuity property. Similarly, the synchronize function interpolates or
fills in values based on the VariableContinuity property of the input timetables.
Create Timetable
Create a timetable that has simulated weather measurements for several days in May
- The timetable variables Tmax and Tmin contain maximum and minimum
temperature readings for each day, and PrecipTotal contains total precipitation for the
day. WXEvent is a categorical array, recording whether certain kinds of weather events,
such as thunder or hail, happened on any given day. The timetable has simulated data
from May 4 to May 10, 2017, but is missing data for two days, May 6th and May 7th.
Date = [datetime(2017,5,4) datetime(2017,5,5) datetime(2017,5,8:10)]';
Tmax = [60 62 56 59 60]';
Tmin = [44 45 40 42 45]';
PrecipTotal = [0.2 0 0 0.15 0]';
WXEvent = [2 0 0 1 0]';
WXEvent = categorical(WXEvent,[0 1 2 3 4],{'None','Thunder','Hail','Fog','Tornado'});
Station1 = timetable(Date,Tmax,Tmin,PrecipTotal,WXEvent)
Station1=5×5 timetable
Date Tmax Tmin PrecipTotal WXEvent
04-May-2017 60 44 0.2 Hail
05-May-2017 62 45 0 None
08-May-2017 56 40 0 None
09-May-2017 59 42 0.15 Thunder
10-May-2017 60 45 0 None
Resample Continuous and Discrete Timetable Variables
One way to fill in data for the two missing days is to use the retime function. If you call
retime without specifying a method, then retime fills in gaps with missing data
10 Timetables