MATLAB Fundamentals>>>Creating Datetimes

本文介绍了如何使用数值输入在Matlab中创建datetime对象,包括指定特定日期和时间、创建一维和二维datetime向量,以及处理像1990年每月第一天这样的周期性数据。
摘要由CSDN通过智能技术生成

Creating datetime Arrays

提示1:If you want to specify the time, use the optional fourth through sixth input arguments in the datetime function. They represent the hour, minute, and second in that order.

t = datetime(2014,5,25,8,11,0)
t =
   25-May-2014 08:11:00
Note that there are either three or six input values for datetime.)

任务1:

Use numeric inputs to create a datetime named d with a value of “February 29th, 2016 17:00”.

解答:

d = datetime(2016,2,29,17,0,0)

提示2:To create vectors and matrices of type datetime you can specify array inputs to the datetime function. Notice that providing a row vector as input produces a row vector, and a column vector as input produces a column vector.

任务2:

Create a 3-by-1 column vector named d2 of type datetime as shown below.

01-Feb-1999
01-Feb-2000
01-Feb-2001

解答:

d2 = datetime([1999;2000;2001],2,1)

任务3:

Create a 1-by-4 row vector named d3 of type datetime representing the dates January 1st-4th, 1975.

解答:

d3 = datetime(1975,1,1:4)

任务4:

Create a 12-by-1 vector d4 of type datetime containing the first day of each month in the year 1990.

解答:

d4 = datetime(1990,1:12,1)'

笔记:

(1)创建时间参数最多6个,年-月-日-时-分-秒;

(2)若要创建 datetime 类型的向量和矩阵,可以指定 datetime 函数的数组输入。请注意,提供行向量作为输入会生成行向量,而作为输入的列向量会生成列向量;

(3)提供列向量的形式可为单个变量写成列向量,例如d2 = datetime([1999;2000;2001],2,1),也可以整体转换为向量,如d4 = datetime(1990,1:12,1)'与d4 = datetime(1990,(1:12)',1))结果是一样的。

  • 13
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值