Main Content

synchronize

Synchronize and resample two timeseries objects using common time vector

Description

Note

This synchronize function applies to objects created using the timeseries function. For information on synchronizing a timetable, which is recommended over timeseries, see synchronize.

[ts1,ts2] = synchronize(ts1,ts2,synchronizemethod) creates two new timeseries objects by synchronizing ts1 and ts2 using a common time vector and the specified method.

example

[ts1,ts2] = synchronize(___,Name,Value) creates the two new timeseries objects with additional options specified by one or more Name,Value pair arguments for the previous syntax.

Examples

collapse all

Create two timeseries objects such that ts1.timeinfo.StartDate is one day after ts2.timeinfo.StartDate.

ts1 = timeseries([1 2],[datestr(now); datestr(now+1)]);
ts2 = timeseries([1 2],[datestr(now-1); datestr(now)]);

Change ts1.timeinfo.StartDate to match ts2.timeinfo.StartDate and change ts1.Time to 1.

[ts1 ts2] = synchronize(ts1,ts2,'union');

The following command preserves ts1.timeinfo.StartDate and keeps ts1.Time as 0.

[ts1 ts2] = synchronize(ts1,ts2,'union','KeepOriginalTimes',true);

Input Arguments

collapse all

First input timeseries, specified as a scalar.

Data Types: timeseries

Second input timeseries, specified as a scalar.

Data Types: timeseries

Synchronize method, specified as one of the following options:

  • 'Union' — Resample timeseries objects using a time vector that is a union of the time vectors of ts1 and ts2 on the time range where the two time vectors overlap.

  • 'Intersection' — Resample timeseries objects on a time vector that is the intersection of the time vectors of ts1 and ts2.

  • 'Uniform' — Requires an additional argument as follows:

    [ts1,ts2] = synchronize(ts1,ts2,'Uniform','Interval',value)
    

    This method resamples time series on a uniform time vector, where value specifies the time interval between two consecutive samples. The uniform time vector is the overlap of the time vectors of ts1 and ts2. The interval units are the smaller units of ts1 and ts2.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: [ts1,ts2] = synchronize(ts1,ts2,'tolerance',1e-13)

Interpolation method for the synchronize operation, specified as 'linear' for linear interpolation or 'zoh' for zero-order hold. The interpolation method can also be specified as tsdata.interpolation object containing a user-defined interpolation method.

Quality codes, specified as [] or a scalar, vector, or multidimensional array of integers ranging from -128 to 127.

  • When the quality code value is a vector, it must have the same length as the time vector. Each element applies to the corresponding data sample.

  • When the quality code value is an array, it must have the same size as the data array. Each element applies to the corresponding data element of the data array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Original time vector, specified as either true to keep the original time values or false to use different time values.

Data Types: logical

Tolerance, specified as a real numeric scalar defining the tolerance for differentiating between two time values of ts1 and ts2. For example, when the sixth time value in ts1 is 5+(1e-12) and the sixth time value in ts2 is 5-(1e-13), both values are treated as 5 by default. To differentiate the two times, you can set 'tolerance' to a smaller value such as 1e-15.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

First output timeseries that was synchronized and resampled, specified as a scalar.

Data Types: timeseries

Second output timeseries that was synchronized and resampled, specified as a scalar.

Data Types: timeseries

Version History

Introduced before R2006a