MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
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×6 timetable
Time Humidity_indoors AirQuality Humidity_outdoors TemperatureF PressureHg
___________________ ________________ __________ _________________ ____________ __________

2015-11-15 00:00:24 36 80 49 51.3 29.61
2015-11-15 01:13:35 36 80 48.919 51.463 29.61
2015-11-15 01:30:24 36.23 79.77 48.9 51.5 29.61
2015-11-15 02:26:47 37 79 48.9 51.5 29.61
2015-11-15 03:00:24 37 80.378 48.9 51.5 29.61

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);
legend(ttHourly.Properties.VariableNames,'Interpreter','none');
xlabel('Time');
ylabel('Normalized Weather Measurements');
title('Mean Daily Weather Trends');

10 Timetables

Free download pdf