필터 지우기
필터 지우기

Datenum failed

조회 수: 8 (최근 30일)
Braden
Braden 2011년 5월 6일
I am using the datenum function to convert a time stamp in my dataset to a serial number. This is the line that does it:
wind.t = datenum(wind.TheTime,'mm/dd/yyyy HH:MM:SS');
It is failing on one dataset and not on another and I don't understand why. There is nothing different between the two datasets, other than one is much longer.
Both timestamps are formatted the same way, but the longer one gives this error:
Error using ==> datenum at 174 DATENUM failed.
Caused by: Error using ==> dtstr2dtnummx Failed on converting date string to date number.
The info about the timestamp column was found using the 'summary' function below. They are identical.
wind = summary(wind)
TheTime: [27878x1 cell string, Units = TheTime]
summary(wind)
TheTime: [2047x1 cell string, Units = TheTime]
Any help or suggestions would be much appreciated.
  댓글 수: 1
Rob Graessle
Rob Graessle 2011년 5월 6일
Does your program fail at the same point every time you run it? What version of MATLAB and operating system are you using?

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

채택된 답변

Matt Tearle
Matt Tearle 2011년 5월 6일
Assuming you haven't looked at every string individually, I'd guess the mostly likely cause is a malformed string somewhere in the cell array. You could perhaps use regexp to check that the strings all do, in fact, match the assumed pattern.
Something like this should work:
nnz(cellfun(@isempty,regexp(wind.TheTime,'\d+/\d+/\d\d\d\d\s+\d+:\d+:\d+')))
  댓글 수: 14
Matt Tearle
Matt Tearle 2011년 5월 10일
@Braden: excellent, glad it's resolved.
@Walter: "Captain DeMorgan"... Let X be the set of all rum-drinkers, and let Y be the set of all pirates...
Walter Roberson
Walter Roberson 2011년 5월 10일
A bit long, but... http://www.youtube.com/watch?v=d67j-Hfgsco

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by