Define Duration Array Inputs - MATLAB & Simulink (original) (raw)

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

Define Duration Array Inputs at the Command Line

Define duration array inputs at the command line by providing an example input or by using a duration coder type. You can also specify a constant duration array input. Alternatively, if you have a test file that calls your entry-point function with example inputs, you can determine the input types by usingcoder.getArgTypes.

Provide an Example Duration Array Input

Use the -args option:

D = duration(1:3,0,0); codegen myFunction -args {D}

Provide a Duration Array Type

To provide a type for a duration array to codegen:

  1. Define a duration array. For example:
  2. Create a type fromD.
  3. Pass the type to codegen by using the-args option.
    codegen myFunction -args {t}

Provide a Constant Duration Array Input

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

D = duration(1:3,0,0); codegen myFunction -args {coder.Constant(C)}

Representation of Duration Arrays

The coder type object displays a succinct description of the object properties while excluding internal state values. The command line interface displays the type and size of nonconstant properties and the values of constant properties. For example, create a coderdatetime type with a size of 1-by-12.

For example, create a coder duration type with a size of 1-by-12.

d = duration((1:3),0,0); dType = coder.typeof(d);

A representation of an empty duration variable is stored in coder type objectdType.

dType =

matlab.coder.type.DurationType 1x3 duration Format : 1x8 char

If necessary, you can obtain the legacy coder.ClassType representation of a duration coder type by using the methodgetCoderType. For example, to view the underlyingcoder.ClassType representation of the dtType object, use this command:

ans =

coder.ClassType 1×1 duration
Properties : millis : 1×:10 double fmt : 1×:12 char

Object Properties

You can edit the properties of coder duration type objects. You can assign scalar values to object properties. Values are implicitly converted to the corresponding coder type values when they are assigned to coder type object properties. You can resize objects themselves by using the coder.resize function or by editing object properties directly.

Resize Object Properties by Using coder.resize

You can resize duration objects and object properties by usingcoder.resize. You can also create arrays within properties.

For example, create a coder duration type with a size of 1-by-12.

d = duration((1:3),0,0); dType = coder.typeof(d)

dType =

matlab.coder.type.DurationType 1x3 duration Format : 1x8 char

Use coder.resize to make the Format property a variable-length character vector with an upper bound of 12.

dType.Format = coder.resize(dType.Format,[1 12],[false true])

dType =

matlab.coder.type.DurationType 1x3 duration Format : 1x:12 char

Resize Objects Directly

You can also resize certain type objects themselves by editing the object properties. For example, to change the number of columns in the dType object, edit the Size property.

dType =

matlab.coder.type.DurationType 1x10 duration Format : 1x:12 char

You can also make the object type variable size by using theVarDims property.

dType.VarDims = [false true]

dType =

matlab.coder.type.DurationType 1x:10 duration Format : 1x:12 char

See Also

duration | coder.Constant | coder.typeof | coder.newtype

Topics