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)
t = 1x12 datetime
Columns 1 through 5
31-Jan-2014
28-Feb-2014
31-Mar-2014
30-Apr-2014
31-May-2014
Columns 6 through 10
30-Jun-2014
31-Jul-2014
31-Aug-2014
30-Sep-2014
31-Oct-2014
Columns 11 through 12
30-Nov-2014
31-Dec-2014
Specify Length and Endpoints of Date or Duration Sequence
This example shows how to use the linspace function to create equally spaced datetime or duration
values between two specified endpoints.
Create a sequence of five equally spaced dates between April 14, 2014 and August 4, 2014. First,
define the endpoints.
A = datetime(2014,04,14);
B = datetime(2014,08,04);
The third input to linspace specifies the number of linearly spaced points to generate between the
endpoints.
C = linspace(A,B,5)
C = 1x5 datetime
14-Apr-2014
12-May-2014
09-Jun-2014
07-Jul-2014
04-Aug-2014
Create a sequence of six equally spaced durations between 1 and 5.5 hours.
A = duration(1,0,0);
B = duration(5,30,0);
C = linspace(A,B,6)
C = 1x6 duration
01:00:00
01:54:00
02:48:00
03:42:00
04:36:00
05:30:00
Sequence of Datetime Values Using Calendar Rules
This example shows how to use the dateshift function to generate sequences of dates and time
where each instance obeys a rule relating to a calendar unit or a unit of time. For instance, each
datetime must occur at the beginning a month, on a particular day of the week, or at the end of a
minute. The resulting datetime values in the sequence are not necessarily equally spaced.
Generate Sequence of Dates and Time
7-17
fall on the last day of each month.
t = datetime(2014,1,31) + calmonths(0:11)
t = 1x12 datetime
Columns 1 through 5
31-Jan-2014
28-Feb-2014
31-Mar-2014
30-Apr-2014
31-May-2014
Columns 6 through 10
30-Jun-2014
31-Jul-2014
31-Aug-2014
30-Sep-2014
31-Oct-2014
Columns 11 through 12
30-Nov-2014
31-Dec-2014
Specify Length and Endpoints of Date or Duration Sequence
This example shows how to use the linspace function to create equally spaced datetime or duration
values between two specified endpoints.
Create a sequence of five equally spaced dates between April 14, 2014 and August 4, 2014. First,
define the endpoints.
A = datetime(2014,04,14);
B = datetime(2014,08,04);
The third input to linspace specifies the number of linearly spaced points to generate between the
endpoints.
C = linspace(A,B,5)
C = 1x5 datetime
14-Apr-2014
12-May-2014
09-Jun-2014
07-Jul-2014
04-Aug-2014
Create a sequence of six equally spaced durations between 1 and 5.5 hours.
A = duration(1,0,0);
B = duration(5,30,0);
C = linspace(A,B,6)
C = 1x6 duration
01:00:00
01:54:00
02:48:00
03:42:00
04:36:00
05:30:00
Sequence of Datetime Values Using Calendar Rules
This example shows how to use the dateshift function to generate sequences of dates and time
where each instance obeys a rule relating to a calendar unit or a unit of time. For instance, each
datetime must occur at the beginning a month, on a particular day of the week, or at the end of a
minute. The resulting datetime values in the sequence are not necessarily equally spaced.
Generate Sequence of Dates and Time
7-17
