Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从给定日期减去 21 个月。
下面给出的我的解决方案只带我到给定年份的第一个月:(
[a,b,c]= datevec(date); b= b-21; datestr(datenum(a,b,c)) %--> 11-Jan-2011 (WRONG).
我希望答案是 2009 年 6 月 11 日。
通过日期数字而不是日期向量并使用addtodate:
addtodate
>> d = datenum(date); >> e = addtodate(d, -21, 'month'); >> datestr(e) ans = 11-Jun-2009