필터 지우기
필터 지우기

how to speedup the function datetime('('1/1/2014 1:00:00 AM','Conve​rtFrom','e​xcel')?

조회 수: 1 (최근 30일)
fan feng
fan feng 2016년 1월 13일
댓글: Are Mjaavatten 2016년 1월 14일
I have a number of date-time values stored in an excel file. The format is '1/1/2014 1:00:00 AM'. I need to convert it into matlab date-time values, so I use the function datetime(). But the trouble is I need to to convert a number of such values, say 10,000, the runtime is rather long. So could I speed up this procedure? I grateful for any help
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 1월 13일
When you read them from the excel files, are they appearing as strings or are they appearing as numeric values ? Excel typically stores dates as floating point values so that is more likely.

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

답변 (1개)

Are Mjaavatten
Are Mjaavatten 2016년 1월 13일
[num,txt,raw] = xlsread('file.xlsx')
returns date-time values as NaNs in the num output and as strings in the txt and raw outputs. I often find it useful to add a new date-time column in the Excel sheet, copying the original, but formatted as a number. The num output will contain this column as numeric values. To convert the date values in column 1 of num from the Excel date format to Matlab:
d = num(:,1) + datenum(1899,12,30);
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 1월 13일
I have definitely seen excel date-time values come out as numeric. It might depend on whether you are using Windows with Excel installed or are using 'basic' mode (everything else)
Are Mjaavatten
Are Mjaavatten 2016년 1월 14일
It seems that Walter's comment is correct unless you are using Windows. And even on Windows, there is a simpler workaround than the one I proposed:
num = xlsread(file,'','','basic');
will return datetime values as numbers. Convert to Matlab's date standard as indicated in my answer above.

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

카테고리

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