Main Content

Define Duration Array Inputs

You can define duration array inputs at the command line or in the MATLAB® Coder™ app. Code generation does not support the programmatic specification of duration 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 using coder.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:

    D = duration(1:3,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 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 coder datetime 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 object dType.

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 method getCoderType. For example, to view the underlying coder.ClassType representation of the dtType object, use this command:

dType.getCoderType
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 using coder.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.Size = [1 10]
dType = 

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

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

dType.VarDims = [false true]
dType = 

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

See Also

| | |

Topics