maize2017的个人博客分享 http://blog.sciencenet.cn/u/maize2017

博文

Matlab 生成指定步长的时间序列

已有 1960 次阅读 2023-3-14 11:48 |个人分类:Matlab|系统分类:科研笔记

% 生成日步长的日期,默认步长1天

t1=datetime(2022,7,5);%生成年月日格式

t2=datetime(2022,7,10);

newdate=t1:t2

newdate = 


  1×6 datetime array


   05-Jul-2022   06-Jul-2022   07-Jul-2022   08-Jul-2022   09-Jul-2022   10-Jul-2022

   

t1=datetime(2022,7,5,8,0,0);%生成年月日时分秒格式

t2=datetime(2022,7,10,8,0,0);

newdate=t1:t2;

newdate = 


  1×6 datetime array


   05-Jul-2022 08:00:00   06-Jul-2022 08:00:00   07-Jul-2022 08:00:00   08-Jul-2022 08:00:00   09-Jul-2022 08:00:00   10-Jul-2022 08:00:00


% 生成指定步长

% 使用caldays函数指定步长为3个日历天

t1=datetime(2022,7,4);

t2=datetime(2022,7,10);

Date_day=(t1:caldays(3):t2)

Date_day = 


  1×3 datetime array


   04-Jul-2022   07-Jul-2022   10-Jul-2022

% 使用hours创建间隔为固定小时步长的时间序列

t1=datetime(2022,7,5,0,0,0);

t2=datetime(2022,7,6,0,0,0);

Date_day=(t1:hours(2):t2);

Date_day = 


  1×13 datetime array


Columns 1 through 7


   05-Jul-2022 00:00:00   05-Jul-2022 02:00:00   05-Jul-2022 04:00:00   05-Jul-2022 06:00:00   05-Jul-2022 08:00:00   05-Jul-2022 10:00:00   05-Jul-2022 12:00:00


Columns 8 through 13


   05-Jul-2022 14:00:00   05-Jul-2022 16:00:00   05-Jul-2022 18:00:00   05-Jul-2022 20:00:00   05-Jul-2022 22:00:00   06-Jul-2022 00:00:00


使用 years、days、minutes 和 seconds 函数,以其他固定长度的日期和时间单位创建日期时间和持续时间的序列。创建 0 到 3 分钟之间的 duration 值序列,增量为 30 秒。 

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

 

1×7 duration array


     0 sec    30 sec    60 sec    90 sec   120 sec   150 sec   180 sec


参考资料:https://code84.com/733044.html




https://blog.sciencenet.cn/blog-3402238-1380313.html

上一篇:MATLAB去除数据中的异常值、离群值以及平滑处理
下一篇:Matlab 绘制土壤含水量Contour图
收藏 IP: 5.78.68.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-26 20:38

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部