datevec() and datenum() fail intermittently with custom format string (MATLAB R2010a)

조회 수: 1 (최근 30일)
Successive calls to datevec() and datenum() with the same argument alternately success and fail. Any ideas on what might be causing this or something I can do to help debug it?
Below is a command-line example, but it happens in functions and scripts too. Note: sometimes (e.g. after a fresh start of MATLAB) it works perfectly every time. (It will probably work perfectly for you, too.)
K>> start_timeTxt
start_timeTxt =
2013-07-16 10:34:59
K>> class(start_timeTxt)
ans =
char
% Nothing abnormal in time string
K>> double(start_timeTxt)
ans =
50 48 49 51 45 48 55 45 49 54 32 49 48 58 51 52 58 53 57
K>> datevec(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
??? Error using ==> dtstr2dtvecmx
Failed on converting date string to date number.
Error in ==> datevec at 124
y = dtstr2dtvecmx(t,icu_dtformat);
% Try it again...
K>> datevec(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
ans =
2013 7 16 10 34 59
% And again...
K>> datevec(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
??? Error using ==> dtstr2dtvecmx
Failed on converting date string to date number.
Error in ==> datevec at 124
y = dtstr2dtvecmx(t,icu_dtformat);
% And a third time...
K>> datevec(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
ans =
2013 7 16 10 34 59
% Is datenum() broken too? Expectedly, yes...:
K>> datenum(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
% but like datevec(), it alternately works too...
K>> datenum(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
ans =
7.3543e+005
K>> datenum(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
K>> datenum(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')
ans =
7.3543e+005
% Try it with literals
>> datenum('2013-07-16 10:34:59', 'yyyy-mm-dd HH:MM:SS')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
>> datenum('2013-07-16 10:34:59', 'yyyy-mm-dd HH:MM:SS')
ans =
7.3543e+005
% In case you are wondering:
K>> which datenum, which datevec
C:\Program Files\MATLAB\R2010a\toolbox\matlab\timefun\datenum.m
C:\Program Files\MATLAB\R2010a\toolbox\matlab\timefun\datevec.m
K>> ver
-------------------------------------------------------------------------------------
MATLAB Version 7.10.0.499 (R2010a) MATLAB License Number: ••••
Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1)
Java VM Version: Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot™ 64-Bit Server VM mixed mode
-------------------------------------------------------------------------------------
K>> memory
Maximum possible array: 4553 MB (4.775e+009 bytes) *
Memory available for all arrays: 4553 MB (4.775e+009 bytes) *
Memory used by MATLAB: 627 MB (6.578e+008 bytes)
Physical Memory (RAM): 4030 MB (4.225e+009 bytes)
* Limited by System Memory (physical + swap file) available.
  댓글 수: 2
dpb
dpb 2013년 7월 27일
It's an earlier version--did you check for bug reports?
All I can suggest is to contact official TMW support; the response will be dependent upon your (or your sponsoring institution's) license status. I don't know when TMW considers EOL for earlier versions.
Since it's in the mex-file your options are somewhat limited...I don't suppose there's anything in common about the sequence of events prior to the time the failures start that you can point to, is there...that'd be too easy. :)
Anyway, since it is in date[num|vec], if after a restart it seems to function correctly for a repeated number of times on the test case, I'd tend to suspect there was a previous execution of a call that caused an internal problem that results in the symptom. That to say that perhaps somewhere earlier in production or development code there's a particular useage of datenum/datevec that is the preciptator--if you could identify such a case perhaps it could lead to some ideas as to cause and potential workaround. Long shot, I agree; unfortunately crystal orb is dark...
per isakson
per isakson 2013년 7월 27일
Have you checked the format string before the call to dtstr2dtvecmx and dtstr2dtnummx, respectively? A mismatch in the format string causes this error:
>> datevec(start_timeTxt, 'yyyy-mmdd HH:MM:SS')
Error using dtstr2dtvecmx
Failed on converting date string to date number.
Error in datevec (line 118)
y = dtstr2dtvecmx(t,icu_dtformat);

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

채택된 답변

Jan
Jan 2013년 7월 27일
편집: Jan 2013년 7월 27일
This is a known bug, see http://www.mathworks.com/support/bugreports/details.html?rp=622845. You find downloadable workarounds there also.
It is always worth to take a look into the list of known bugs in case of problems.
  댓글 수: 2
Jim Tonti
Jim Tonti 2013년 7월 28일
Jan- Thanks for the quick response. Since upgrading wasn't an option, and the bug was incredibly consistent, I had implemented the 'try-catch' workaround with success. It's good to see this rather strange bug has been fixed in future releases - it had me going for a while. Software is one of the places where insanity rules: doing the same thing and expecting (and getting!) different results. You have to love it!
Jan
Jan 2013년 7월 28일
@Jim: This bug has been fixed for the following releases and for your release also - you find the required new functions in the bug report.
It seems to be a simple problem with an uninitialized static variable and it is strange that such a bug was not found before the release.

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

추가 답변 (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