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

8 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 15 Nov 2017
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

Sign in to comment.

Answers (3)

Greg
Greg on 15 Nov 2017
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 on 15 Nov 2017
Try this,
data = readtable('Teste2.csv');
data.Time = datetime(datevec(data.Time),'Format','HH:mm:ss.SSS');

Jeremy Hughes
Jeremy Hughes on 15 Nov 2017
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

Community Treasure Hunt

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

Start Hunting!