Main Content

Code Generation for Datetime Arrays

The values in adatetimearray represent points in time using the proleptic ISO calendar.

When you usedatetimearrays with code generation, adhere to these restrictions.

Define Datetime Arrays for Code Generation

For code generation, use thedatetimefunction to createdatetimearrays. For example, suppose the input arguments to your MATLAB®function are numeric arrays whose values indicate the year, month, day, hour, minute, and second components for a point in time. You can create adatetimearray from these input arrays.

functiond = foo(y,mo,d,h,mi,s)%#codegend = datetime(y,mo,d,h,mi,s);end

Allowed Operations on Datetime Arrays

For code generation, you are restricted to the operations ondatetimearrays listed in this table.

Operation Example Notes

Assignment operator:=

d = datetime(2019,1:12,1,12,0,0); d(1) = datetime(2019,1,31);

不支持使用assignm生成代码金宝appent operator=to:

  • Delete an element.

  • Expand the size of adatetimearray.

Relational operators:< > <= >= == ~=

d = datetime(2019,1:12,1,12,0,0); tf = d(1) < d(2);

Code generation supports relational operators.

Indexing operation

d = datetime(2019,1:12,1,12,0,0); idx = [1 2]; d(idx); idx = logical([1 1 0]); d(idx);

Code generation supports indexing by position, linear indexing, and logical indexing.

Concatenation

d1 = datetime(2019,1:6,1,12,0,0); d2 = datetime(2019,7:12,1,12,0,0); d = [d1 d2];

Code generation supports concatenation ofdatetimearrays.

MATLABToolbox Functions That Support Datetime Arrays

For code generation, you can usedatetimearrays with these MATLAB toolbox functions:

Related Topics