Datetime Array Limitations for Code Generation
When you create datetime arrays in MATLAB® code that you intend for code generation, you must specify the values by using
the datetime function. See Dates and Time.
For datetime arrays, code generation does not support the following
inputs and operations:
Text inputs. For example, specifying a character vector as the input argument produces an error.
function d = foo() %#codegen d = datetime('2019-12-01'); end
The
'Format'name-value pair argument. You cannot specify the display format by using thedatetimefunction, or by setting theFormatproperty of adatetimearray. To use a specific display format, create adatetimearray in MATLAB, then pass it as an input argument to a function that is intended for code generation.The
'TimeZone'name-value pair argument and theTimeZoneproperty. When you usedatetimearrays in code that is intended for code generation, they must be unzoned.Setting time component properties. For example, setting the
Hourproperty in the following code produces an error:d = datetime; d.Hour = 2;
Growth by assignment. For example, assigning a value beyond the end of an array produces an error.
function d = foo() %#codegen d = datetime(2019,1:12,1,12,0,0); d(13) = datetime(2020,1,1,12,0,0); end
Deleting an element. For example, assigning an empty array to an element produces an error.
function d = foo() %#codegen d = datetime(2019,1:12,1,12,0,0); d(1) = []; end
Converting
datetimevalues to text by using thechar,cellstr, orstringfunctions.
Limitations that apply to classes also apply to datetime arrays. For
more information, see MATLAB Classes Definition for Code Generation (MATLAB Coder).