Main Content

Categorical Array Limitations for Code Generation

When you create categorical arrays in MATLAB® code that you intend for code generation, you must specify the categories and elements of each categorical array by using the categorical function. See Categorical Arrays.

For categorical arrays, code generation does not support the following inputs and operations:

  • Arrays of MATLAB objects.

  • Sparse matrices.

  • Duplicate category names when you specify them using the categoryNames input argument of the categorical function.

  • Growth by assignment. For example, assigning a value beyond the end of an array produces an error.

    function c = foo() %#codegen
        c = categorical(1:3,1:3,{'small','medium','large'});
        c(4) = 'medium';
    end
    
  • Adding a category. For example, specifying a new category by using the = operator produces an error, even when the categorical array is unprotected.

    function c = foo() %#codegen
        c = categorical(1:3,1:3,{'small','medium','large'});
        c(1) = 'extra-large';
    end
    
  • Deleting an element. For example, assigning an empty array to an element produces an error.

    function c = foo() %#codegen
        c = categorical(1:3,1:3,{'small','medium','large'});
        c(1) = [];
    end
    
  • Converting categorical values to text by using the char or string functions. To convert elements of a categorical array to text, use the cellstr function.

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

See Also

|

Related Topics