MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
t = 1x3 datetime array
01-Nov-2013 08:00:00 03-Nov-2013 08:00:00 05-Nov-2013 08:00:00

Specify a step size in units other than days. Create a sequence of datetime values spaced
18 hours apart.

t = t1:hours(18):t2

t = 1x6 datetime array
Columns 1 through 3

01-Nov-2013 08:00:00 02-Nov-2013 02:00:00 02-Nov-2013 20:00:00

Columns 4 through 6

03-Nov-2013 14:00:00 04-Nov-2013 08:00:00 05-Nov-2013 02:00:00

Use the years, days, minutes, and seconds functions to create datetime and duration
sequences using other fixed-length date and time units. Create a sequence of duration
values between 0 and 3 minutes, incremented by 30 seconds.

d = 0:seconds(30):minutes(3)

d = 1x7 duration array
0 sec 30 sec 60 sec 90 sec 120 sec 150 sec 180 sec

Compare Fixed-Length Duration and Calendar Duration Step Sizes

Assign a time zone to t1 and t2. In the America/New_York time zone, t1 now occurs
just before a daylight saving time change.

t1.TimeZone = 'America/New_York';
t2.TimeZone = 'America/New_York';

If you create the sequence using a step size of one calendar day, then the difference
between successive datetime values is not always 24 hours.

t = t1:t2;
dt = diff(t)

dt = 1x4 duration array
24:00:00 25:00:00 24:00:00 24:00:00

7 Dates and Time

Free download pdf