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

I have exactly the same problem (R2012a) - it really just seems to be an unstable function. Whenever it starts happening, I just restart Matlab and it works fine again for a while.

于 2013-10-03T01:52:53.830 に答える