Effacer les filtres
Effacer les filtres

Settings for readtable for date and timestamp columns

4 vues (au cours des 30 derniers jours)
Purnendu Nath
Purnendu Nath le 23 Mai 2019
Modifié(e) : per isakson le 23 Mai 2019
I have a CSV file that looks like this and I want to use readtable() to load up the Date and Time columns so that they are numerical. (rather than 'cell' or 'string').
Is there a set of options for doing that in readtable? I know I can loop programmatically and convert each entry from char/string with datenum but want to avoid that overhead.
I have tried
T = readtable( filename, 'Delimiter', ',' ...
, 'HeaderLines', 0 ...
, 'ReadVariableNames', true ...
, 'Format', '%s%s%s%f%f' ...
, 'FileType', 'text' ...
, 'ReadRowNames', false ...
, 'TreatAsEmpty','N/A' ...
, 'TextType', 'string' ...
, 'DatetimeType', 'datetime' )
Ticker Date Time BuyPrice SellPrice
ACC-II.NFO 15/05/2019 10:10:04 1582.9 1588.95
ACC-II.NFO 15/05/2019 10:10:04 1582.9 1588.95
ACC-II.NFO 15/05/2019 10:10:04 1582.9 1588.95
ACC-II.NFO 15/05/2019 10:10:04 1582.9 1588.95
ACC-II.NFO 15/05/2019 10:10:16 1584 1588.35
  2 commentaires
Walter Roberson
Walter Roberson le 23 Mai 2019
Which MATLAB release are you using? Dealing with times got easier in recent releases.
Is it really necessary that you use numeric entries for those? Most of the time it makes more sense to combine the date and time into a single datetime object.
Purnendu Nath
Purnendu Nath le 23 Mai 2019
Thanks Walter... I have decided to use
T.Time = frac(datenum(T.Time, 'hh:MM:ss'))
and
T.Date = datenum(T.Date,'dd/mm/yyyy')
and then may use datetime.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by