Synchronize Timetables
The timetables, indoors and outdoors, contain different measurements taken inside and outside a
building at different times. Combine all the data into one timetable with the synchronize function.
tt = synchronize(indoors,outdoors);
tt(1:5,:)
ans=5×5 timetable
Time
Humidity_indoors
AirQuality
Humidity_outdoors
TemperatureF
___________________
________________
__________
_________________
____________
2015-11-15 00:00:24
36
80
49
51.3
2015-11-15 01:13:35
36
80
NaN
NaN
2015-11-15 01:30:24
NaN
NaN
48.9
51.5
2015-11-15 02:26:47
37
79
NaN
NaN
2015-11-15 03:00:24
NaN
NaN
48.9
51.5
The output timetable, tt contains all the times from both timetables. synchronize puts a missing
data indicator where there are no data values to place in tt. When both input timetables have a
variable with the same name, such as Humidity, synchronize renames both variables and adds
both to the output timetable.
Synchronize the timetables again, and this time fill in missing data values with linear interpolation.
ttLinear = synchronize(indoors,outdoors,'union','linear');
ttLinear(1:5,:)
ans=5×5 timetable
Time
Humidity_indoors
AirQuality
Humidity_outdoors
TemperatureF
___________________
________________
__________
_________________
____________
2015-11-15 00:00:24
36
80
49
51.3
2015-11-15 01:13:35
36
80
48.919
51.463
2015-11-15 01:30:24
36.23
79.77
48.9
51.5
2015-11-15 02:26:47
37
79
48.9
51.5
2015-11-15 03:00:24
37
80.378
48.9
51.5
Adjust Data in One Timetable
You also can adjust the data in a single timetable to a new time vector. Calculate the means of the
variables in ttLinear over six-hour intervals with the retime function. If any rows have NaN values
after you adjust the data, remove them with the rmmissing function.
tv = [datetime(2015,11,15):hours(6):datetime(2015,11,18)];
ttHourly = retime(ttLinear,tv,'mean');
ttHourly = rmmissing(ttHourly);
Plot Timetable Data
Normalize the data in ttHourly to the mean for each variable in the timetable. Plot the mean daily
values of these measurements. You can use the Variables property of a timetable to access the
variables. ttHourly.Variables returns the same variables as ttHourly{:,:}.
ttMeanVars = ttHourly.Variables./mean(ttHourly.Variables);
plot(ttHourly.Time,ttMeanVars);
Create Timetables
10-3
The timetables, indoors and outdoors, contain different measurements taken inside and outside a
building at different times. Combine all the data into one timetable with the synchronize function.
tt = synchronize(indoors,outdoors);
tt(1:5,:)
ans=5×5 timetable
Time
Humidity_indoors
AirQuality
Humidity_outdoors
TemperatureF
___________________
________________
__________
_________________
____________
2015-11-15 00:00:24
36
80
49
51.3
2015-11-15 01:13:35
36
80
NaN
NaN
2015-11-15 01:30:24
NaN
NaN
48.9
51.5
2015-11-15 02:26:47
37
79
NaN
NaN
2015-11-15 03:00:24
NaN
NaN
48.9
51.5
The output timetable, tt contains all the times from both timetables. synchronize puts a missing
data indicator where there are no data values to place in tt. When both input timetables have a
variable with the same name, such as Humidity, synchronize renames both variables and adds
both to the output timetable.
Synchronize the timetables again, and this time fill in missing data values with linear interpolation.
ttLinear = synchronize(indoors,outdoors,'union','linear');
ttLinear(1:5,:)
ans=5×5 timetable
Time
Humidity_indoors
AirQuality
Humidity_outdoors
TemperatureF
___________________
________________
__________
_________________
____________
2015-11-15 00:00:24
36
80
49
51.3
2015-11-15 01:13:35
36
80
48.919
51.463
2015-11-15 01:30:24
36.23
79.77
48.9
51.5
2015-11-15 02:26:47
37
79
48.9
51.5
2015-11-15 03:00:24
37
80.378
48.9
51.5
Adjust Data in One Timetable
You also can adjust the data in a single timetable to a new time vector. Calculate the means of the
variables in ttLinear over six-hour intervals with the retime function. If any rows have NaN values
after you adjust the data, remove them with the rmmissing function.
tv = [datetime(2015,11,15):hours(6):datetime(2015,11,18)];
ttHourly = retime(ttLinear,tv,'mean');
ttHourly = rmmissing(ttHourly);
Plot Timetable Data
Normalize the data in ttHourly to the mean for each variable in the timetable. Plot the mean daily
values of these measurements. You can use the Variables property of a timetable to access the
variables. ttHourly.Variables returns the same variables as ttHourly{:,:}.
ttMeanVars = ttHourly.Variables./mean(ttHourly.Variables);
plot(ttHourly.Time,ttMeanVars);
Create Timetables
10-3
