Problems With readtable. Convert string data in datetime with milissecond precision.
6 次查看(过去 30 天)
显示 更早的评论
Hi! I try to read the csv file attached, with this command:
t = readtable('Test2.csv','Format','%{HH:mm:ss;SSS}D,%f%f%f%f')
But returns the error:
"Unable to read the DATETIME data with the format 'HH:mm:ss;SSS'. If the data is not a time, use %q to get text data."
My First column is in correct format. How i fix this? I'm using the R2017b version
Thanks a lot!
1 个评论
Stephen23
2017-11-15
In case anyone is interested, here are the first four rows of the file:
Time,GVPos,VlvLimCmd,SpeedCtrlSP,Speed,PIDOut
12:38:06.865,6.021393,8,102.5,102.412323,6.069856
12:38:06.915,6.021393,8,102.5,102.408577,6.076125
12:38:06.965,6.021393,8,102.5,102.400078,6.082932
回答(3 个)
Greg
2017-11-15
You aren't accounting for your header row:
Time,GVPos,VlvLimCmd,SpeedCtrlSP,Speed,PIDOut
"Time" is clearly not in the datetime format.
Assuming you've handled that separately, your first column is NOT in the correct format:
12:38:06.865,6.021393,8,102.5,102.412323,6.069856
That is clearly a period "." not a semicolon ";" between seconds and fractional seconds.
Thank you for posting your actual code (and not a billion lines of useless fluff around it), as well as your actual test data. This makes for an amazingly simple and unambiguous question, and makes it extremely easy and desirable for us to want to help you.
0 个评论
KL
2017-11-15
Try this,
data = readtable('Teste2.csv');
data.Time = datetime(datevec(data.Time),'Format','HH:mm:ss.SSS');
0 个评论
Jeremy Hughes
2017-11-15
Your time seems to have a decimal separator of '.' it's the semicolon that's the issue.
t = readtable('Test2.csv','Format','%{HH:mm:ss.SSS}D%f%f%f%f')
Jeremy
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!