Main Content

Table Limitations for Code Generation

When you create tables in MATLAB® code that you intend for code generation, you must create them by using the array2table, cell2table, struct2table, or table functions. For more information, see Tables.

For tables, code generation has these limitations:

  • You must specify variables names using the 'VariableNames' name-value pair argument when creating tables from input arrays by using the table, array2table, or cell2table functions.

    You do not have to specify the 'VariableNames' argument when you preallocate a table by using the table function and the 'Size' name-value pair argument.

  • Table variable names do not have to be valid MATLAB identifiers. The names must be composed of ASCII characters, but can include any ASCII characters (such as commas, dashes, and space characters).

  • You cannot change the VariableNames, RowNames, DimensionNames, or UserData properties of a table after you create it.

    You can specify the 'VariableNames' and 'RowNames' input arguments when you create a table. These input arguments specify the properties.

  • To pass table indices into generated code as input arguments, first make the indices constant by using the coder.Constant function. If table indices are not constant, then indexing into variables produces an error.

  • You cannot add custom metadata to a table. The addprop and rmprop functions are not supported.

  • You cannot change the size of a table by assignments. For example, adding a new row produces an error.

    function T = foo() %#codegen
        T = table((1:3)',(1:3)','VariableNames',{'Var1','Var2'});
        T(4,2) = 5;

    Deleting a row or a variable also produces an error.

  • When you preallocate a table, you can specify only the following data types by using the 'VariableTypes' name-value pair argument.

    Data Type Name

    Initial Value in Each Element


    Double- or single-precision 0

    'doublenan', 'doubleNaN''singlenan', 'singleNaN'

    Double- or single-precision NaN


    Signed 8-, 16-, 32-, or 64-bit integer 0


    Unsigned 8-, 16-, 32-, or 64-bit integer 0


    0 (false)


    0 seconds, as a duration value


    {''} (cell with 0-by-0 character array)

    If you specify 'char' as a data type, then table preallocates the corresponding variable as a cell array of character vectors, not as a character array. Best practice is to avoid creating table variables that are character arrays.

  • When you vertically concatenate tables, they must have the same variable names in the same order. In MATLAB, the variable names must be the same but can be in different orders.

  • When you horizontally concatenate tables, and the tables have row names, they must have the same row names in the same order. In MATLAB, the row names must be the same but can be in different orders.

  • If two tables have variables that are N-D cell arrays, then the tables cannot be vertically concatenated.

  • You cannot use curly braces to extract data from multiple table variables that are N-D cell arrays, since this operation is horizontal concatenation.

  • The set membership functions intersect, setdiff, setxor, and union support unsorted tables in all cases. You do not have to specify the 'stable' option.

  • When using the movevars function, the input argument vars cannot contain duplicate variable names.

  • When using the convertvars function:

    • Function handles are not supported.

    • The second and third input arguments (vars and dataType) must be constant.

    • You cannot specify dataType as 'char'.

Limitations that apply to classes also apply to tables. For more information, see MATLAB Classes Definition for Code Generation.

See Also

| | |

Related Topics