MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   在Matlab中从给定日期减去月份 (https://www.labfans.com/bbs/showthread.php?t=26573)

poster 2019-12-14 20:13

在Matlab中从给定日期减去月份
 
我需要从给定的日期减去21个月。

下面给出的解决方案仅将我带到给定年份的第一个月:(

[a,b,c]= datevec(date); b= b-21; datestr(datenum(a,b,c)) %--> 11-Jan-2011 (WRONG). 我希望答案是2009年6月11日。



[B]回答:[/B]

通过日期数字而不是日期向量,然后使用addtodate :

>> d = datenum(date); >> e = addtodate(d, -21, 'month'); >> datestr(e) ans = 11-Jun-2009

[url=https://stackoverflow.com/questions/5275404]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 09:12

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.