Convert timestamps in CSV file to seconds using readtable and table2timetable
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2018-3-11
编辑:dpb
2018-3-11
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.
采纳的回答
Jeremy Hughes
2018-3-11
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 个评论
dpb
2018-3-13
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...
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!