How to Convert Timeseries​/TimeTable​/Duration to Double.

46 views (last 30 days)
I have a data set of type TimeTable in matlab and I need to use the data from the timetable as inputs for a simulink block. If there are any simple approaches to this please let me know, below is my approach.
The end goal for my approach is a 2 row matrix- row 1 contains vector timestamps of samples, row 2 contains vector of data at each time sample. These vectors can be saved as a .mat file and easily replayed in simulink.
1. Convert timetable to a table (this creates a 2 column table - column 1 for time, column 2 for data)
2. Create an empty (zeros) 2 row matrix of same length as table (# rows of table)
3. I can then easily store the data (column 2 of table) into the second row of the matrix
4. I would like to store timestamps into the first row of the matrix however this is where I am stuck.
Any idea how to convert a table column of timestamps to a vector of doubles? (timestamps are in seconds starting from 0 seconds).
When I try put the column into the space, it complains that it is of type 'duration' and not double and therefore will not work.

Accepted Answer

Ameer Hamza
Ameer Hamza on 3 May 2018
Suppose your timetable array is TT, then try following
timeList = TT.(TT.Properties.DimensionNames{1}) % or you can simpley use TT.(name of your time column)
timsInSeconds = seconds(timeList - timeList(1));

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!