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 次查看(过去 30 天)
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.

采纳的回答

Eric Sofen
Eric Sofen 2018-3-20
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 个评论
Eric Sofen
Eric Sofen 2018-3-20
编辑:Eric Sofen 2018-3-20
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 2018-3-22
Thank you very much Eric. This is the approach that worked for me. It really works well. Thank you for your time and effort!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Time Series Collections 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by