www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SynchronizeTimetablesToArbitraryTimeVectorExample.m

    %% Synchronize Timetables to Arbitrary Time Vector
% Synchronize two small timetables with weather measurements to an
% arbitrary time vector. Use linear interpolation to resample data for
% times in the time vector that do not match row times from the input timetables.
%
% Load two small timetables, with row times for measurements taken at the
% half-hour mark. However, in each timetable, there is a row time for data 
% that was not collected at the half-hour mark. Both timetables are irregular, 
% which means that the time step is different between consecutive row times.
load(fullfile(matlabroot,'examples','matlab','halfHoursTT'));

%% 
% Display the timetables. |TT1| and |TT2| have three rows and different variables.
TT1
TT2

%%
% Specify a time vector that includes some of the row times from each
% timetable.
newTimes = datetime('2015-12-18 08:30:00') + hours(0:1:2)

%%
% Synchronize |TT1| and |TT2| to |newTimes|. The |newTimes| vector has
% times that are not row times of |TT1| or |TT2|. To interpolate data values
% for times in |newTimes| that do not match row times in |TT1| or |TT2|, specify 
% |'linear'|.
TT = synchronize(TT1,TT2,newTimes,'linear')