How to go about grouping, listing and (if user specifies) writing to a file a group of time series objects which are of different lengths (# of rows) and different time bases?

1 visualización (últimos 30 días)
I am trying to group the various time series objects into a single data structure ( currently I'm doing this with a cell data structure). But I need to have a way to see the whole data listed when I double click on the cell from the Workspace. Also I need to have a way to have this data printed if the user specifies. Additionally, I need to have a single time column being the first column of the cell and have the data shown for the correct times at which there's data available (e.g. tsObj1 may have data at t1 but tsObj2 may not have data at t1 until perhaps t3 but the cell would show times t1, t2, t3 with tsObj1 column having data at t1 and t2 having blanks (or NaN) for times t1 and t2).
In summary, Want to have
t tsObj1 tsObj2
-- ------------ -------------
t1 datatsObj1_1 NaN
t2 datatsObj1_2 NaN
t3 datatsObj1_3 datatsObj2_1
I really would like to use timetable() and/or tscollection() but I am unable to use these things because my data have different number of rows. (How do I go about making all of my timeseries objects have the same number of rows?).
Thank you for your help, effort, advice, time.

Respuesta aceptada

Eric Sofen
Eric Sofen el 20 de Mzo. de 2018
Take a look at the synchronize function for timetables. By default, synchronize(tt1,tt2) will construct a new time table with a time vector that is the union of the time vectors of tt1 and tt2. If there is data for a particular time in tt1 but not tt2 (or vice versa), which is what leads to the timetables being different lengths, it will fill with a missing value (e.g. NaN).
  3 comentarios
Eric Sofen
Eric Sofen el 20 de Mzo. de 2018
Editada: Eric Sofen el 20 de Mzo. de 2018
One issue you're running into is that the time vector in a timetable must be a datetime or duration datatype, but in timeseries it's stored as a double. Also, make sure that both the data and time are column vectors. To convert your timeseries to timetable, you need to pull out the vectors from the timeseries and pass them into the timetable constructor. Something like this:
tt1 = timetable(seconds(m1.Time), m1.Data(:))
tt2 = timetable(seconds(m2.Time), m2.Data(:))
tt = synchronize(tt1,tt2)
theBlueGreenMtrx
theBlueGreenMtrx el 22 de Mzo. de 2018
Thank you very much Eric. This is the approach that worked for me. It really works well. Thank you for your time and effort!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by