# 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`

.

`[`

creates two new `ts1`

,`ts2`

]
= synchronize(`ts1`

,`ts2`

,`synchronizemethod`

)`timeseries`

objects by synchronizing
`ts1`

and `ts2`

using a common time vector
and the specified method.

`[`

creates the two new `ts1`

,`ts2`

]
= synchronize(___,`Name,Value`

)`timeseries`

objects with additional options
specified by one or more `Name,Value`

pair arguments for the
previous syntax.

## Examples

### Synchronize `timeseries`

Objects

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

`ts1`

— First input `timeseries`

scalar

First input `timeseries`

, specified as a scalar.

**Data Types: **`timeseries`

`ts2`

— Second input `timeseries`

scalar

Second input `timeseries`

, specified as a scalar.

**Data Types: **`timeseries`

`synchronizemethod`

— Synchronize method

`'Union'`

| `'Intersection'`

| `'Uniform'`

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)
```

`InterpMethod`

— Interpolation method

`'linear'`

(default) | `'zoh'`

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.

`QualityCode`

— Quality codes

`[]`

(default) | scalar | vector | multidimensional array

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`

`KeepOriginalTimes`

— Original time indicator

`true`

| `false`

Original time vector, specified as either `true`

to
keep the original time values or `false`

to use
different time values.

**Data Types: **`logical`

`tolerance`

— Tolerance

`1e-10`

(default) | real numeric scalar

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

`ts1`

— First output `timeseries`

scalar

First output `timeseries`

that was synchronized and
resampled, specified as a scalar.

**Data Types: **`timeseries`

`ts2`

— Second output `timeseries`

scalar

Second output `timeseries`

that was synchronized and
resampled, specified as a scalar.

**Data Types: **`timeseries`

## Version History

**Introduced before R2006a**

## See Also

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)