Matching two time series by one of their time vector

Hello,
I'm trying to match several data sets to have them matching the same time vector. I assume that time vector of ts1 is the proper one and now I want to match the other ts2 in such a manner that the new ts3 shares the ts1 time vector. I want to have second data set with "holes" in data when the time vectors do not match. I don't want to interpolate the second data set - only match it to the vector.
Another way is to match both data sets to the new, ideal time vector .
Tried the "synchronize" function but it interpolates the data and I don't want that to happen.
It can be also NaNs instead of empty "holes" in the matched data.
thanks for help!
By a hole I refer to missing data in one of the time series for a given ideal time vector. I need to create new data set consisting of both data sets with new ideal, uniform time vector. The missing data will be seen as a hole in the new data set.
Example:
ts1 ts2
Time Data Time Data
1 0.2 1 0.4
2 0.4 2 1.6
3 0.3 5 2.0
4 1.4 6 0.1
5 0.1 7 2.4
6 0.9 8 3.1
New time serie should look like this:
Time Data1 Data2
1 0.2 0.4
2 0.4 1.6
3 0.3
4 1.4
5 0.1 2.0
6 0.9 0.1
7 2.4
8 3.1
To complicate more, the time is not an integer but fraction of a day in a year sequence .

1 comentario

Jan
Jan el 27 de Jul. de 2011
Please post some example data. It is not clear what a "hole" is.

Iniciar sesión para comentar.

 Respuesta aceptada

Oleg Komarov
Oleg Komarov el 28 de Jul. de 2011
If you have:
t1 = [1 0.2
2 0.4
3 0.3
4 1.4
5 0.1
6 0.9];
t2 = [1 0.4
2 1.6
5 2.0
6 0.1
7 2.4
8 3.1];
% Recombine the inputs:
In = [[ ones(length(t1),1) t1]
[2*ones(length(t2),1) t2]];
Pivot(In)
%{ The result:
ans =
NaN 1.00 2.00
1.00 0.20 0.40
2.00 0.40 1.60
3.00 0.30 NaN
4.00 1.40 NaN
5.00 0.10 2.00
6.00 0.90 0.10
7.00 NaN 2.40
8.00 NaN 3.10
%}

4 comentarios

Jakub Bialek
Jakub Bialek el 28 de Jul. de 2011
My example here was simplified one. In reality the ts1 and ts2 are different dimensions arrays so: ??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Oleg Komarov
Oleg Komarov el 28 de Jul. de 2011
The concept of Pivot is that you have to supply a 3 colum matrix. The first column should be the ID of your series, the second column are dates and the third are values. If you can get to that type of input the rest is handled by Pivot.
Jakub Bialek
Jakub Bialek el 28 de Jul. de 2011
But my real matrix of values is 6000x320, time vector is stored in separate variable. I can join values ad time into one matrix but the other matrix of values (the one I have to match the first matrix to) is of different shape and length...
Oleg Komarov
Oleg Komarov el 28 de Jul. de 2011
You can unPivot the matrixes into n by 3 matrixes concatenate them and Pivot them back.
To unPivot the first element should be NaN, the first row should contain IDs and the first column the dates (look at the ans in my example above)

Iniciar sesión para comentar.

Más respuestas (2)

Fangjun Jiang
Fangjun Jiang el 27 de Jul. de 2011

0 votos

Would this post give you a clue?

1 comentario

Jakub Bialek
Jakub Bialek el 28 de Jul. de 2011
Well, this would only detect beginning of such gap, but wouldn't determine how big it was, would it?

Iniciar sesión para comentar.

Martina Raffellini
Martina Raffellini el 17 de Jul. de 2018
Editada: Martina Raffellini el 17 de Jul. de 2018
Hi, I had the same problem as you, but the synchronize function does work. It does not necessarily interpolate if you do not specify so, NaN values were inserted where data were missing.
you can see it in the 1st example, "Synchronize Timetables and Insert Missing Data Indicators", here: https://it.mathworks.com/help/matlab/ref/synchronize.html?searchHighlight=Synchronize&s_tid=doc_srchtitle
Maybe your first code was looked like the 2nd example? this uses linear interpolation

Categorías

Preguntada:

el 27 de Jul. de 2011

Editada:

el 17 de Jul. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by