필터 지우기
필터 지우기

Settings for readtable for date and timestamp columns

조회 수: 4 (최근 30일)
Purnendu Nath
Purnendu Nath 2019년 5월 23일
편집: per isakson 2019년 5월 23일
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
Walter Roberson
Walter Roberson 2019년 5월 23일
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 2019년 5월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by