Azzera filtri
Azzera filtri

Settings for readtable for date and timestamp columns

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 23 Mag 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 il 23 Mag 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by