Borrar filtros
Borrar filtros

Create a time series collection from two timeseries with different TimeInfo Vector

6 visualizaciones (últimos 30 días)
Meh
Meh el 24 de Nov. de 2014
Respondida: Jaynik el 15 de Jul. de 2024 a las 5:38
I created two timeseries objects using
ts=timeseries(Data,Time);
Time is datenumber. Both timeseries have different start and end time but the second one is a subset of the first. Both the timeseries have the following TimeInfo:
Common Properties:
Units: 'seconds'
Format: ''
StartDate: ''
But when I try to combine them in a Timeseriescollection using:
tsc=tscollection(ts1);
tsc=addts(tsc,ts2);
, I am getting the following error:
Error using tscollection/addts>localCheckTS (line 142)
The time vector of the time series you are adding must match the tscollection time
vector.
Error in tscollection/addts (line 80)
localCheckTS(h,data);
Can anybody help me how to solve this problem.

Respuestas (1)

Jaynik
Jaynik el 15 de Jul. de 2024 a las 5:38
Hi,
The error message suggests that the time vectors of the two timeseries objects are not identical. In MATLAB, the time vector of the timeseries object must match the time vector of the "tscollection".
Even though ts2 is a subset of ts1, if their time vectors are not identical, you will still encounter this error. This is because "tscollection" objects require all contained timeseries to have the same time vector.
To resolve this, you can use the resample function to make the time vectors of ts1 and ts2 identical. Following is a sample code for the same:
ts1_resampled = resample(ts1, ts2.Time);
tsc = tscollection(ts1_resampled);
tsc = addts(tsc, ts2);
In this code, ts1 is resampled at the time points of ts2, creating a new timeseries ts1_resampled that has the same time vector as ts2. Then, ts1_resampled and ts2 can be added to the same "tscollection" without any errors.
You can read more about "resample" here:
Please note that resampling might introduce NaNs in the data if ts2’s time vector contains points that are not in ts1’s time vector. You might need to handle these NaNs depending on your specific use case.
Hope this helps!

Categorías

Más información sobre Time Series en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by