# How to synchronize multiple timeseries

85 views (last 30 days)
David Doria on 7 May 2013
Commented: Steven Lord on 27 Aug 2019
The synchronize() function only takes 2 timeseries arguments. What is the standard procedure if you need to sync more than 2 timeseries? I tried to sync (one of the outputs of syncing timeseries 1 and 2) with timeseries 3, but the results are not synced (e.g. the same length) (as shown below) because it simply has to do with the range of the time data:
% Create data set 1
t1 = rand(10,1);
data1=rand(10,1);
ts1=timeseries(data1,t1);
% Create data set 2
t2 = rand(8,1);
data2=rand(length(t2), 1);
ts2=timeseries(data2,t2);
% Create data set 3
t3 = rand(5,1);
data3=rand(length(t3), 1);
ts3=timeseries(data3,t3);
% Sync 1 and 2
[uniform_ts12_1 uniform_ts12_2] = synchronize(ts1,ts2,'Uniform','Interval',.1);
% Sync 3 to one of the results of the (sync of 1 and 2)
[uniform_ts13_1 uniform_ts13_3] = synchronize(uniform_ts12_1,ts3,'Uniform','Interval',.1);
disp('New sizes:')
length(uniform_ts12_1.Data)
length(uniform_ts12_2.Data)
length(uniform_ts13_1.Data)
length(uniform_ts13_3.Data)
The problem is that the lengths of uniform_ts12_1, uniform_ts12_2, uniform_ts13_1, and length(uniform_ts13 are not the same. It syncs 2 with 1, but then if 3 is outside (or well inside) the bounds of 2, it syncs them to the smaller one (3), which is now not the same length as the sync between 1 and 2.
Can anyone suggest how to sync 3 timeseries so they all have identical time data at the end of the day?
Thanks,
David
Sebastian on 8 Nov 2013
This is of importance to me as well

Andy Campbell on 17 May 2014
##### 2 CommentsShowHide 1 older comment
Steven Lord on 27 Aug 2019
You've stored your timetable arrays as elements of a cell array rather than individually numbered variables, right? The general consensus is that individually numbered variables have some significant drawbacks.
If so, use that cell array as a comma-separated list when calling synchronize (see the "Function Call Arguments" item under the "How to Use the Comma-Separated Lists" section on that documentation page.)
x = {4, 8, 15, 16, 23, 42};
y = [x{:}]