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
Define datetime array inputs at the command line by providing an example input or by
using a datetime
coder type. You can also specify a constant datetime
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 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
:
Define a
datetime
array. For example:D = datetime(2019,1:12,1,12,0,0);
Create a type from
D
.t = coder.typeof(D);
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)}
Representation of Datetime 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.
dt = datetime(2019,1:12,1,12,0,0); dtType = coder.typeof(dt)
The representation of variable dt
is stored in coder type object
dtType
.
dtType = matlab.coder.type.DatetimeType 1x12 datetime Format : 1x0 char TimeZone : 1x0 char
If necessary, you can obtain the legacy coder.ClassType
representation of a datetime
coder type by using the method
getCoderType
. For example, to view the underlying
coder.ClassType
representation of the dtType
object,
use this
command:
dtType.getCoderType
ans = coder.ClassType 1×1 datetime Properties : data : 1×:24 double complex fmt : 1×:12 char tz : 1×0 ch
Object Properties
You can edit the properties of coder datetime
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 datetime
objects and object properties by using
coder.resize
. You can also create arrays within properties.
For example, create a coder datetime
type with a size of
1-by-12.
dt = datetime(2019,1:12,1,12,0,0); dtType = coder.typeof(dt)
dtType = matlab.coder.type.DatetimeType 1x12 datetime Format : 1x0 char TimeZone : 1x0 char
Use coder.resize
to make the Format
property
variable-length with an upper bound of
12.
dtType.Format = coder.resize(dtType.Format,[1 12],[false true])
dtType = matlab.coder.type.DatetimeType 1x12 datetime Format : 1x:12 char TimeZone : 1x0 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 dtType
object, edit
the Size
property.
dtType.Size = [1 24]
dtType = matlab.coder.type.DatetimeType 1x24 datetime Format : 1x:12 char TimeZone : 1x0 char
You can also make the number of rows variable size by using the
VarDims
property.
dtType.VarDims = [false true]
dtType = matlab.coder.type.DatetimeType 1x:24 datetime Format : 1x:12 char TimeZone : 1x0 char
See Also
datetime
| coder.Constant
| coder.typeof
| coder.newtype