Synchronize and resample two timeseries
objects using common
time vector
[
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.
timeseries
ObjectsCreate 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);
ts1
— First input timeseries
First input timeseries
, specified as a scalar.
Data Types: timeseries
ts2
— Second input timeseries
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
.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
[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 arrayQuality 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 indicatortrue
| 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'
— Tolerance1e-10
(default) | real numeric scalarTolerance, 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
ts1
— First output timeseries
First output timeseries
that was synchronized and
resampled, specified as a scalar.
Data Types: timeseries
ts2
— Second output timeseries
Second output timeseries
that was synchronized and
resampled, specified as a scalar.
Data Types: timeseries
set
| synchronize
| timeseries
You have a modified version of this example. Do you want to open this example with your edits?