Specify a format character vector in readtable

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

dpb
dpb il 8 Lug 2018
Modificato: dpb il 8 Lug 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.

Più risposte (1)

dpb
dpb il 8 Lug 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 Commenti
alpedhuez
alpedhuez il 8 Lug 2018
I got the above warning from
S=timerange('07/01/2003','10/30/2017');
Please advise.
dpb
dpb il 8 Lug 2018
See Answer with the additional info...

Accedi per commentare.

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by