Settings for readtable for date and timestamp columns

8 Ansichten (letzte 30 Tage)
Purnendu Nath
Purnendu Nath am 23 Mai 2019
Bearbeitet: per isakson am 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 Kommentare
Walter Roberson
Walter Roberson am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by