www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AddCalendarDurationToCreateSequenceOfDatesExample.m
%% Add Duration or Calendar Duration to Create Sequence of Dates % This example shows how to add a duration or calendar duration % to a datetime to create a sequence of datetime values. %% % Create a datetime scalar representing November 1, 2013 at 8:00 AM. % Copyright 2015 The MathWorks, Inc. t1 = datetime(2013,11,1,8,0,0); %% % Add a sequence of fixed-length % hours to the datetime. t = t1 + hours(0:2) %% % Add a sequence of calendar months to the datetime. t = t1 + calmonths(1:5) %% % Each datetime in |t| occurs on the first day of each month. %% % Verify that the dates in |t| are spaced 1 month apart. dt = caldiff(t) %% % Determine the number of days between each date. dt = caldiff(t,'days') %% % Add a number of calendar months to the date, January 31, 2014, to create % a sequence of dates that fall on the last day of each month. t = datetime(2014,1,31) + calmonths(0:11)