不稳定的"日期"代码,有时有效,有时无效



我有一个非常简单的代码,如下所示,

[Y M] = datevec(datenum({'199812';'201203'},'yyyymm'));   
    % Y returns the # of years,
    % M is the # of months other                            
    % than a full year                                    
mns = diff([Y M])*[12;1];                                 
    % mns is the total # of months
    % between 12/1998 to 03/2012                          
Monthdate = cellstr(datestr(datenum(1998,12+(0:mns)',1),'yyyymm')); 
    % Returns cells as
    %199812,199901,199902,                                        
    %199003,...201203

有时此代码运行良好。有时它会返回,

Error using datenum (line 181)
DATENUM failed.
Caused by:
    Error using dtstr2dtnummx
    Failed on converting date string to date number.

它怎么会不稳定?有没有办法让它稳定下来?

我也有同样的问题(R2012a)——它看起来确实是一个不稳定的函数。每当它开始发生时,我只要重新启动Matlab,它就会再次正常工作一段时间。

相关内容

最新更新