我有一个非常简单的代码如下,
[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.
怎么可能不稳定?有没有办法让它稳定?