Main Content

Duration Array Limitations for Code Generation

When you create duration arrays in MATLAB® code that you intend for code generation, you must specify the durations by using the duration, years, days, hours, minutes, seconds, or milliseconds functions. See Dates and Time.

For duration 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 = duration('01:30:00');
    end
    
  • Growth by assignment. For example, assigning a value beyond the end of an array produces an error.

    function d = foo() %#codegen
        d = duration(1:3,0,0);
        d(4) = hours(4);
    end
    
  • Deleting an element. For example, assigning an empty array to an element produces an error.

    function d = foo() %#codegen
        d = duration(1:3,0,0);
        d(1) = [];
    end
    
  • Converting duration values to text by using the char, cellstr, or string functions.

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

See Also

| | | | | |

Related Topics