Main Content

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 the datetime function, or by setting the Format property of a datetime array. To use a specific display format, create a datetime array 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 the TimeZone property. When you use datetime arrays in code that is intended for code generation, they must be unzoned.

  • Setting time component properties. For example, setting the Hour property 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 datetime values to text by using the char, cellstr, or string functions.

Limitations that apply to classes also apply to datetime arrays. For more information, see MATLAB Classes Definition for Code Generation (MATLAB Coder).

See Also

|

Related Topics