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_timeTxtstart_timeTxt = 2013-07-16 10:34:59K>> 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 57K>> datevec(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')??? Error using ==> dtstr2dtvecmxFailed 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 ==> dtstr2dtvecmxFailed 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 182DATENUM 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+005K>> datenum(start_timeTxt, 'yyyy-mm-dd HH:MM:SS')??? Error using ==> datenum at 182DATENUM 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 182DATENUM 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 datevecC:\Program Files\MATLAB\R2010a\toolbox\matlab\timefun\datenum.mC:\Program Files\MATLAB\R2010a\toolbox\matlab\timefun\datevec.mK>> 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>> memoryMaximum 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.
Best Answer