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

조회 수: 4 (최근 30일)
Meh
Meh 2014년 11월 24일
답변: Jaynik 2024년 7월 15일
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.

답변 (1개)

Jaynik
Jaynik 2024년 7월 15일
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!

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by