使用默认步长
从 2013 年 11 月 1 日开始至 2013 年 11 月 5 日结束,创建日期时间值的序列。默认步长为一个日历天。
t1 = datetime(2013,11,1,8,0,0);
t2 = datetime(2013,11,5,8,0,0);
t = t1:t2
t = 1x5 datetime
Columns 1 through 3
01-Nov-2013 08:00:00 02-Nov-2013 08:00:00 03-Nov-2013 08:00:00
Columns 4 through 5
04-Nov-2013 08:00:00 05-Nov-2013 08:00:00
指定步长
使用 caldays 函数指定步长为 2 个日历天。
t = t1:caldays(2):t2
t = 1x3 datetime
01-Nov-2013 08:00:00 03-Nov-2013 08:00:00 05-Nov-2013 08:00:00
用天以外的其他单位指定步长。创建间隔为 18 小时的日期时间值序列。
t = t1:hours(18):t2
t = 1x6 datetime
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
使用 years、days、minutes 和 seconds 函数,以其他固定长度的日期