0

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

[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.

怎么可能不稳定?有没有办法让它稳定?

4

1 回答 1

0

我有完全相同的问题(R2012a) - 它真的只是似乎是一个不稳定的功能。每当它开始发生时,我只需重新启动 Matlab,它就会再次正常工作一段时间。

于 2013-10-03T01:52:53.830 回答