MATLAB Answers

Read Date time series format

40 views (last 30 days)
Jogger on 17 Aug 2019
Edited: per isakson on 14 Sep 2019
I want to read Date and time series from below format
% file.txt has time formatted data
% 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 (line 82)
In (line 18)
In (line 122)
In (line 25)
In (line 98)
Jogger on 19 Aug 2019

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

Sign in to comment.

Accepted Answer

Jogger on 20 Aug 2019
milliseconds information is in place(.SSSSSS)but conversion is not done properly.
Jogger on 21 Aug 2019
Thanks a lot for your efforts.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 19 Aug 2019
S = fileread('update_engine.txt');
timestamps = regexp(S, '^.(.{18})', 'lineanchors', 'match');
ts_dt = datetime(timestamps, 'InputFormat', 'MMdd/HHmmss.SSSSSS');
Walter Roberson
Walter Roberson on 20 Aug 2019
You can change the Format property to display the milliseconds.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!