%% Interpolation of Dates and Times
% Interpolate time-stamped data points.
% Consider a data set containing temperature readings that are measured every four hours. Create a table with one day's worth of data and plot the data.

x = (datetime(2016,1,1):hours(4):datetime(2016,1,2))';
x.Format = 'MMM dd, HH:mm';
T = [31 25 24 41 43 33 31]';
WeatherData = table(x,T,'VariableNames',{'Time','Temperature'})
plot(WeatherData.Time, WeatherData.Temperature, 'o')

%
% Interpolate the data set to predict the temperature reading during each minute of the day. Since the data is periodic, use the 'spline' interpolation method.

xq = (datetime(2016,1,1):minutes(1):datetime(2016,1,2))';
V = interp1(WeatherData.Time, WeatherData.Temperature, xq, 'spline');

%
% Plot the interpolated points.

hold on
plot(xq,V,'r')

% Copyright 2012 The MathWorks, Inc.