Settings for readtable for date and timestamp columns

8 visualizaciones (últimos 30 días)
Purnendu Nath
Purnendu Nath el 23 de Mayo de 2019
Editada: per isakson el 23 de Mayo de 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 comentarios
Walter Roberson
Walter Roberson el 23 de Mayo de 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 el 23 de Mayo de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by