Read Date time series format

13 ビュー (過去 30 日間)
Life is Wonderful
Life is Wonderful 2019 年 8 月 17 日
編集済み: per isakson 2019 年 9 月 14 日
I want to read Date and time series from below format
% file.txt has time formatted data
[0803/135825.745523:GGBB:main.cc(182)]
[0803/135825.746634:NNFF:boat_control_xhramyos.cc(137)]
% My Code is as follows
VariableNames = {'Date'};
VariableWidths = [20]
VariableTypes = {'datetime'};
opts = fixedWidthImportOptions('VariableNames','SelectedVariableNames', [1]);
opts = setvaropts(opts, 'Date', 'InputFormat', 'MMdd/HHmmss.SSSSSS');
Content.update_engine = readtable('file.txt', opts);
I am getting following error as I am unable to read the time properly.
Warning: Unable to convert one or more variables to datetime. Specify the correct
InputFormat and DatetimeLocale properties in the DatetimeVariableImportOptions.
> In matlab.io.internal.functions.ReadTableWithImportOptionsText/executeImpl (line 82)
In matlab.io.internal.functions.ReadTableWithImportOptions/executeImpl (line 18)
In matlab.io.internal.functions.ReadTableWithImportOptionsText/execute (line 122)
In matlab.io.internal.functions.ReadTableWithImportOptions/execute (line 25)
In matlab.io.internal.functions.ExecutableFunction/validateAndExecute (line 98)
  8 件のコメント
Guillaume
Guillaume 2019 年 8 月 19 日
Can you please suggest someting else that is easy to do
Stick to one file format, the fixed width one in your previous question. Or use an even better one (e.g. comma delimited with text in quoted strings)
Otherwise, I'm afraid there's no easy way to do it. You'll have to use regexp or write your own parser.
Life is Wonderful
Life is Wonderful 2019 年 8 月 19 日

OK if no other choices left .Can you please help me with sample script here

サインインしてコメントする。

採用された回答

Life is Wonderful
Life is Wonderful 2019 年 8 月 20 日
milliseconds information is in place(.SSSSSS)but conversion is not done properly.
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 8 月 20 日
The conversion looks perfect when I try.
timestamps.Format = 'dd-MMM-uuuu HH:mm:ss.SSSSSS';
>> timestamps(1:2)
ans =
1×2 datetime array
03-Aug-2019 13:58:25.745523 03-Aug-2019 13:58:25.746634
>> S(1:100)
ans =
'[0803/135825.745523:INFO:main.cc(182)] A/B Update Engine starting
[0803/135825.746634:INFO:boot_cont'
745523 and 746634 exactly match the input text.
Life is Wonderful
Life is Wonderful 2019 年 8 月 21 日
Thanks a lot for your efforts.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 19 日
S = fileread('update_engine.txt');
timestamps = regexp(S, '^.(.{18})', 'lineanchors', 'match');
ts_dt = datetime(timestamps, 'InputFormat', 'MMdd/HHmmss.SSSSSS');
  4 件のコメント
Life is Wonderful
Life is Wonderful 2019 年 8 月 20 日
Thanks a lot Walter.
Why I don't see the milliseconds information "timestamps" ? Any help
Walter Roberson
Walter Roberson 2019 年 8 月 20 日
You can change the Format property to display the milliseconds.

サインインしてコメントする。

カテゴリ

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