Convert timestamps in CSV file to seconds using readtable and table2timetable

11 views (last 30 days)
Hello,
I found several solutions for converting timestamps to seconds (by eliminating year, month, day...), but none of them worked. How can I use readtable() and table2timetable() for converting the timestamps in my CSV file to seconds? Attached you can find the CSV file. My goal is to plot gX, gY, gZ in terms of time. What is the most efficient way of applying that?
Thanks
  2 Comments
dpb
dpb on 11 Mar 2018
Edited: dpb on 11 Mar 2018
First you need to create the input file with sufficient precision to differentiate between samples (or eliminate the repeated timestamps in some fashion).
After you do that, I suspect you'll have better luck using the timeseries object than the datetime or timetable to use linear time instead of calendar time for plotting as the duration time object is hamstrung for less than seconds intervals it appears.
Or, just revert to the old datenum and treat the absicssa as purely numeric and fixup the axes using the datetimeruler manually.
YH
YH on 11 Mar 2018
thanks for the reply. Which function should I use to read the CSV file and import the TimeStamps data to timeseries? Can you give example for using timeseries as required?

Sign in to comment.

Accepted Answer

Jeremy Hughes
Jeremy Hughes on 11 Mar 2018
This will work as long as the times are on the same day (as in the file).
T = readtable(file,'Format','%{dd-MMM-uuuu HH:mm:ss.SS}D%f%f%f')
times = timeofday(T.TimeStamp);
times.Format = 'hh:mm:ss.SSS';
TT = table2timetable(T(:,2:end),'RowTimes',times)
you can also subtract datetimes, which would make them elapsed times since start. Not sure what you're looking for.
times = T.TimeStamp - T.TimeStamp(1)
  10 Comments
dpb
dpb on 13 Mar 2018
Depending upon what you're trying to do with the data you might also be able to interpolate the time vector to backfill the missing times accurately enough...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!