Main Content

Define Datetime Array Inputs

You can define datetime array inputs at the command line or in the MATLAB® Coder™ app. Code generation does not support the programmatic specification of datetime input types by using function argument validation (arguments blocks) or by using preconditioning (assert statements).

Define Datetime Array Inputs at the Command Line

Use one of these procedures:

Alternatively, if you have a test file that calls your entry-point function with example inputs, you can determine the input types by using coder.getArgTypes.

Provide an Example Datetime Array Input

Use the -args option:

D = datetime(2019,1:12,1,12,0,0);
codegen myFunction -args {D}

Provide a Datetime Array Type

To provide a type for a datetime array to codegen:

  1. Define a datetime array. For example:

    D = datetime(2019,1:12,1,12,0,0);
    

  2. Create a type from D.

    t = coder.typeof(D);
    

  3. Pass the type to codegen by using the -args option.

    codegen myFunction -args {t}
    

Provide a Constant Datetime Array Input

To specify that a datetime array input is constant, use coder.Constant with the -args option:

D = datetime(2019,1:12,1,12,0,0);
codegen myFunction -args {coder.Constant(C)}

Define Datetime Array Inputs in the MATLAB Coder App

Use one of these procedures:

Representation of Datetime Arrays

A coder type object for a datetime array describes the object and its properties. Use coder.typeof or pass datetime as a string scalar to coder.newtype.

The coder type object displays a succinct description of the object properties while excluding internal state values. Nonconstant properties display their type and size, while constant properties display only their values. For example:

t = datetime(2019,1:12,1,12,0,0);
tType = coder.typeof(t)

The representation of variable t is stored in coder type object tType.

tType = 

   matlab.coder.type.DatetimeType
     1x12 datetime
	  Format : 1x0 char
	TimeZone : 1x0 char

If your workflow requires the legacy representation of coder type objects, use the getCoderType function on the variable that has the new representation of your class or object. See Legacy Representation of Coder Type Objects.

Resize Object Properties by Using coder.resize

You can resize most objects by using coder.resize. You can resize objects, its properties and create arrays within the properties.

For a datetime coder object, you can resize the object properties:

t = datetime(2019,1:12,1,12,0,0);
tType = coder.typeof(t)
tType.Format = coder.resize(tType.Format, [1 12])

This code resizes the Format property to be a 1x12 char property.

tType = 

   matlab.coder.type.DatetimeType
     1x12 datetime
	  Format : 1x12 char
	TimeZone : 1x0 char

You can also resize the object by using coder.resize. See Edit and Represent Coder Type Objects and Properties.

See Also

| | |

Related Topics