MATLAB Fundamentals>>>Creating Datetimes

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))结果是一样的。

你可能感兴趣的:(算法,matlab)