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

7 ビュー (過去 30 日間)
Felipe Fonseca
Felipe Fonseca 2017 年 11 月 15 日
回答済み: Jeremy Hughes 2017 年 11 月 15 日
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 Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by