Main Content

Table Limitations for Code Generation

If you create tables, modify them, or use table functions in MATLAB® code that you intend for code generation, then code generation has limitations described in the next sections. Limitations that apply to classes also apply to tables. For more information on class limitations, see MATLAB Classes Definition for Code Generation (MATLAB Coder).

Creating Tables Limitations

If your MATLAB code creates tables, then code generation has these limitations.

Inputs for Table Creation

Limitations

Any inputs

  • Table variable names do not have to be valid MATLAB identifiers. The names must be composed of ASCII characters, which can include commas, dashes, and space characters.

Table created from input arrays

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

Table created with preallocated variables

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

  • You can specify only the following data types by using the 'VariableTypes' name-value argument:

    • 'double'

    • 'single'

    • 'doublenan' or 'doubleNaN'

    • 'singlenan' or 'singleNaN'

    • 'int8''int16''int32', or 'int64'

    • 'uint8''uint16''uint32', or 'uint64'

    • 'logical'

    • 'duration'

    • 'cellstr'

    • 'char'

Modifying Tables Limitations

If your MATLAB code modifies data in a table or its properties, then code generation has these limitations.

Table Operation or Property

Limitations

VariableNames, RowNames, DimensionNames, or UserData properties

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

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

Table indices that specify variables as input arguments to generated code

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

Custom metadata

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

Assignments that change size of table

  • 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;
    end
    

    Deleting a row or a variable also produces an error.

Vertical concatenation

  • 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 in the tables.

Horizontal concatenation

  • 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 in the tables.

Table variables that are N-D cell arrays

  • 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 because this operation is horizontal concatenation.

Using Table Functions Limitations

If your MATLAB code uses the functions listed in the table, then code generation has these limitations.

Function

Limitations

convertvars

  • Function handles are not supported.

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

  • You cannot specify dataType as 'char'.

intersect

setdiff

setxor

union

  • These functions support unsorted tables in all cases. You do not have to specify the 'stable' option.

issortedrows

  • The input argument vars must be constant.

  • If any table variables have multiple columns, then those variables must have fixed widths.

join

  • In general, input tables cannot have nonkey variables with the same names. However, you can specify duplicated variable names in the input tables by using:

    • 'KeepOneCopy'

    • 'LeftVariables' and 'RightVariables'

  • The values of these name-value arguments must be constant:

    • 'Keys'

    • 'LeftKeys'

    • 'RightKeys'

    • 'LeftVariables'

    • 'RightVariables'

    • 'KeepOneCopy'

  • Nested tables are not supported.

movevars

  • The input argument vars cannot contain duplicate variable names.

rows2vars

  • The input table cannot be variable-size.

  • The 'VariableNamesSource' name-value argument is not supported.

  • The value of the 'DataVariables' name-value argument must be constant.

  • The value of the 'VariableNamingRule' name-value argument must be constant.

  • If you assign row names to the input table, then the vector of row names must be constant.

sortrows

  • The input argument vars must be constant.

  • If tblA has a variable that is a cell array of character vectors with multiple columns, then you cannot sort the table using the values in that variable.

splitvars

  • The value of the 'NewVariableNames' name-value argument must be constant.

  • The variables that are split cannot have a variable number of columns.

stack

  • The second input argument, vars, must be constant.

  • The values of the 'ConstantVariables', 'NewDataVariableName', and 'IndexVariableName' name-value arguments must be constant.

unstack

  • The 'NewDataVariableNames' name-value argument must be specified. Its value must be constant.

  • The vars and ivars input arguments (data variables and indicator variables) must be constant.

  • If you specify grouping variables and constant variables, then they must be constant.

  • If you specify an aggregation function, then it must be constant.

  • If a variable of the input table is a cell array of character vectors, then unstack fills empty cells in the corresponding output variable with 1-by-0 character arrays in the generated code. In MATLAB, unstack fills such gaps with 0-by-0 character arrays.

  • The unstack function does not support code generation when the input table has a variable that is a heterogeneous cell array that cannot be converted to a homogeneous cell array.

    • If the input has a variable that is a homogeneous cell array, or that can be converted to one, then the 'AggregationFunction' name-value argument must be specified. The default value of 'AggregationFunction' is 'unique'. But the unique function does not support cell arrays.

varfun

  • The function handle input, func, must be constant.

  • While function handles can be inputs to varfun itself, they cannot be inputs to your entry point functions. Specify func within the code meant for code generation. For more information, see Function Handle Limitations for Code Generation (MATLAB Coder).

  • The values for all name-value arguments must be constant.

  • The 'ErrorHandler' name-value argument is not supported for code generation.

  • Variable-size input arguments are not supported.

  • Grouping variables cannot have duplicate values in generated code.

  • You cannot specify the value of 'OutputFormat' as 'cell' if you specify the 'GroupingVariables' name-value argument and the function returns a different data type for each variable specified by 'InputVariables'.

  • If you specify groups and the number of groups is not known at compile time, and that number is zero, then empty double variables in the output might have sizes of 1-by-0 in generated code. In MATLAB, such variables have sizes of 0-by-0.

See Also

| | |

Related Topics