Problems With readtable. Convert string data in datetime with milissecond precision.

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

KL
KL 2017-11-15
Try this,
data = readtable('Teste2.csv');
data.Time = datetime(datevec(data.Time),'Format','HH:mm:ss.SSS');

Jeremy Hughes
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

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by