Define Table Inputs
You can define table inputs at the command line or in the MATLAB®
Coder™ app. Code generation does not support the programmatic specification of
table
input types by using function argument validation (arguments
blocks)
or by using preconditioning (assert
statements).
Define Table Inputs at the Command Line
Use one of these procedures:
Alternatively, if you have a test file that calls your entry-point function with example
inputs, you can determine the input types by using
coder.getArgTypes
.
Provide an Example Table Input
Use the -args
option:
T = table(A,B,C,'VariableNames',vnames); codegen myFunction -args {T}
Provide a Table Type
To provide a type for a table to codegen
:
Define a table. For example:
T = table(A,B,C,'VariableNames',vnames);
Create a type from
T
.t = coder.typeof(T);
Pass the type to
codegen
by using the-args
option.codegen myFunction -args {t}
Provide a Constant Table Input
To specify that a table input is constant, use coder.Constant
with the
-args
option:
T = table(A,B,C,'VariableNames',vnames); codegen myFunction -args {coder.Constant(T)}
Define Table Inputs in the MATLAB Coder App
Use one of these procedures:
Representation of Tables
A coder type object for a table describes the object and its properties. Use coder.typeof
or pass table
as a string scalar to coder.newtype
.
The coder type object displays a succinct description of the object properties while excluding internal state values. Nonconstant properties display their type and size, while constant properties display only their values. For example:
A = [1 2 3]'; B = [4 5 6]'; C = [7 8 9]'; t = table(A,B,C); tType = coder.typeof(t)
The representation of variable t
is stored in coder type object
tType
.
tType = matlab.coder.type.TableType 3x3 table Data : 1x3 homogeneous cell Description : 1x0 char UserData : 0x0 double DimensionNames : {'Row'} {'Variables'} VariableNames : {'A'} {'B'} {'C'} VariableDescriptions : 1x3 homogeneous cell VariableUnits : 1x3 homogeneous cell VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity RowNames : 0x0 homogeneous cell
If your workflow requires the legacy representation of coder type objects, use the
getCoderType
function on the variable that has the new representation
of your class or object. See Legacy Representation of Coder Type Objects.
Resize Object Properties by Using coder.resize
You can resize most objects by using coder.resize
. You can resize objects, its properties and create arrays
within the properties.
For a table
coder object, you can resize the object
properties:
A = [1 2 3]'; B = [4 5 6]'; C = [7 8 9]'; t = table(A,B,C); tType = coder.typeof(t) tType.Description = coder.resize(tType.Description,[1 12],[0 1])
This code resizes the Description
property to be a
1x:12
char
property which has an upper bound of 12
.
tType = matlab.coder.type.TableType 3x3 table Data : 1x3 homogeneous cell Description : 1x:12 char UserData : 0x0 double DimensionNames : {'Row'} {'Variables'} VariableNames : {'A'} {'B'} {'C'} VariableDescriptions : 1x3 homogeneous cell VariableUnits : 1x3 homogeneous cell VariableContinuity : 1x3 matlab.internal.coder.tabular.Continuity RowNames : 0x0 homogeneous cell
You can also resize the object by using coder.resize
. See Edit and Represent Coder Type Objects and Properties.
See Also
table
| coder.Constant
| coder.typeof