MATLAB Answers

Specify a format character vector in readtable

46 views (last 30 days)
alpedhuez
alpedhuez on 7 Jul 2018
Commented: dpb on 8 Jul 2018
I ran "readtable" and got a following warning. Please advise how to specify a format character vector in readtable. It was not clear from the documentation.
Warning: Successfully read the date/time text using the format 'MM/dd/uuuu', but
their format is ambiguous and could also be 'dd/MM/uuuu'. Specify a format
character vector to avoid ambiguity.

  0 Comments

Sign in to comment.

Accepted Answer

dpb
dpb on 8 Jul 2018
Edited: dpb on 8 Jul 2018
Ah! That's an internal problem in that timerange calls datetime.
Unfortunately, there's a quality of implementation problem; TMW didn't provide the means to specify the date string format for timerange to pass on to its helper function.
Fortunately for your specific case being the common convention, it did make the proper choice but to avoid the warning message you will have to recode the input format to use a datetime value directly...
>> timerange(datetime('07/01/2003','format','MM/dd/yyyy'),datetime('10/30/2017','format','MM/dd/yyyy'))
ans =
timetable timerange subscript:
Select timetable rows with times in the half-open interval:
[01-Jul-2003 00:00:00, 30-Oct-2017 00:00:00)
See Select Timetable Data by Row Time and Variable Type.
>>
This is worth an official enhancement request to be able to write
timerange('07/01/2003','10/30/2017'},'format','MM/dd/yyyy')
to pass the format string on. Surprising TMW didn't do enough pre-release testing to have uncovered the issue and fixed it before release into the wild, but a lot of the datetime stuff really hasn't been fully implemented early on--I guess time-to-market outranks thoroughness and completion of features.

  1 Comment

Sign in to comment.

More Answers (1)

dpb
dpb on 8 Jul 2018
It's not as trivial as the error message makes it seem, granted...there's only the named parameter 'Format' available as input option readtable-Format which will require then specifying the format for every column in the input file, not just one for the datetime entry.
The alternative is to use the importoptions functions, or, if you're only doing this once or twice't for a given file, just use importool

  2 Comments

alpedhuez
alpedhuez on 8 Jul 2018
I got the above warning from
S=timerange('07/01/2003','10/30/2017');
Please advise.
dpb
dpb on 8 Jul 2018
See Answer with the additional info...

Sign in to comment.

Sign in to answer this question.

Products