Define Timetable Inputs
You can define timetable inputs at the command line or in the
MATLAB®
Coder™ app. Code generation does not support the programmatic specification of
timetable input types by using function argument validation (arguments blocks)
or by using preconditioning (assert statements).
Define Timetable Inputs at the Command Line
Define timetable inputs at the command line by providing an example input or by using a
timetable coder type. You can also specify a constant timetable
input. 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 Timetable Input
Use the -args
option:
TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames); codegen myFunction -args {TT}
Provide a Timetable Type
To provide a type for a timetable to codegen:
Define a timetable. For example:
TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames);
Create a type from
T.t = coder.typeof(TT);
Pass the type to
codegenby using the-argsoption.codegen myFunction -args {t}
Provide a Constant Timetable Input
To specify that a timetable input is constant, use coder.Constant with the -args
option:
TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames); codegen myFunction -args {coder.Constant(TT)}
Representation of Timetables
The coder type object displays a succinct description of the object properties while
excluding internal state values. The command line interface displays the type and size of
nonconstant properties and the values of constant properties. For example, create a coder
timetable type with a size of 5-by-2.
tt = timetable((1:5)',(11:15)','SampleRate',1);
ttType = coder.typeof(tt)The representation of variable tt is stored in coder type object
ttType.
ttType =
matlab.coder.type.RegularTimetableType
5x2 timetable
Data : 1x2 homogeneous cell
Description : 1x0 char
UserData : 0x0 double
DimensionNames : {'Time'} {'Variables'}
VariableNames : {'Var1'} {'Var2'}
VariableDescriptions : 1x2 homogeneous cell
VariableUnits : 1x2 homogeneous cell
VariableContinuity : 1x2 matlab.internal.coder.tabular.Continuity
StartTime : 1x1 matlab.coder.type.DurationType
SampleRate : 1x1 double
TimeStep : 1x1 matlab.coder.type.DurationTypeDefine a regular timetable by specifying the
SampleRate or TimeStep. You can also define an
irregular timetable by specifying the RowTimes. For
example:
tti = timetable((1:3)','RowTimes',seconds(1:3));
ttiType = coder.typeof(tti)The representation of irregular table tti is stored in coder type
object ttiType.
ttiType =
matlab.coder.type.TimetableType
3x1 timetable
Data : 1x1 homogeneous cell
Description : 1x0 char
UserData : 0x0 double
DimensionNames : {'Time'} {'Variables'}
VariableNames : {'Var1'}
VariableDescriptions : 1x1 homogeneous cell
VariableUnits : 1x1 homogeneous cell
VariableContinuity : 1x1 matlab.internal.coder.tabular.Continuity
RowTimes : 3x1 matlab.coder.type.DurationTypeIf necessary, you can obtain the legacy coder.ClassType
representation of a timetable coder type by using the method
getCoderType. For example, to view the underlying
coder.ClassType representation of the ttType object,
use this
command:
ttType.getCoderType
ans =
coder.ClassType
1×1 timetable
Properties :
data : 1×2 homogeneous cell
base: 5×1 double
metaDim : 1×1 matlab.internal.coder.tabular.private.metaDim
Properties :
labels : {'Time'} {'Variables'}
length : 1×1 double
rowDim : 1×1 matlab.internal.coder.tabular.private.implicitRegularRowTimesDim
Properties :
length : 5
specifiedAsRate : 1×1 logical
startTime : 1×1 duration
Properties :
millis : 1×1 double
fmt : 1×1 char
sampleRate : 1×1 double
timeStep : 1×1 duration
Properties :
millis : 1×1 double
fmt : 1×1 char
varDim : 1×1 matlab.internal.coder.tabular.private.varNamesDim
Properties :
descrs : 1×2 homogeneous cell
base: 1×0 char
units : 1×2 homogeneous cell
base: 1×0 char
continuity : 1×2 matlab.internal.coder.tabular.Continuity
customProps : 1×1 struct with no fields
hasDescrs : 1×1 logical
hasUnits : 1×1 logical
hasContinuity : 1×1 logical
hasCustomProps : 1×1 logical
labels : {'Var1'} {'Var2'}
length : 1×1 double
arrayProps : 1×1 struct
Description: 1×0 char
UserData: 0×0 doubleObject Properties
You can edit the properties of coder timetable type objects. You can
assign scalar values to object properties. Values are implicitly converted to the
corresponding coder type values when they are assigned to coder type object properties. You
can resize objects themselves by using the coder.resize function or by editing object properties
directly.
Resize Object Properties by Using coder.resize
You can resize timetable objects and object properties by using
coder.resize. You can also create arrays within properties.
For example, create a coder timetable type with a size of 5-by-2.
The Description property has a size of
1-by-0.
tt = timetable((1:5)',(11:15)','SampleRate',1);
ttType = coder.typeof(tt)
ttType =
matlab.coder.type.RegularTimetableType
5x2 timetable
Data : 1x2 homogeneous cell
Description : 1x0 char
UserData : 0x0 double
DimensionNames : {'Time'} {'Variables'}
VariableNames : {'Var1'} {'Var2'}
VariableDescriptions : 1x2 homogeneous cell
VariableUnits : 1x2 homogeneous cell
VariableContinuity : 1x2 matlab.internal.coder.tabular.Continuity
StartTime : 1x1 matlab.coder.type.DurationType
SampleRate : 1x1 double
TimeStep : 1x1 matlab.coder.type.DurationTypeUse coder.resize to make UserData a
variable-size column vector with an upper bound of
10.
ttType.UserData = coder.resize(ttType.UserData,[10 1],[true false])
ttType =
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 cellResize Objects Directly
You can also resize certain type objects themselves by editing the object properties.
For example, to change the number of rows in the tType object, edit the
Size
property.
ttType.Size = [10 2]
ttType =
matlab.coder.type.RegularTimetableType
10x2 timetable
Data : 1x2 homogeneous cell
Description : 1x0 char
UserData : :10x1 double
DimensionNames : {'Time'} {'Variables'}
VariableNames : {'Var1'} {'Var2'}
VariableDescriptions : 1x2 homogeneous cell
VariableUnits : 1x2 homogeneous cell
VariableContinuity : 1x2 matlab.internal.coder.tabular.Continuity
StartTime : 1x1 matlab.coder.type.DurationType
SampleRate : 1x1 double
TimeStep : 1x1 matlab.coder.type.DurationType
You can also make the number of rows variable size by using the
VarDims
property.
ttType.VarDims = [true false]
ttType =
matlab.coder.type.RegularTimetableType
:10x2 timetable
Data : 1x2 homogeneous cell
Description : 1x0 char
UserData : :10x1 double
DimensionNames : {'Time'} {'Variables'}
VariableNames : {'Var1'} {'Var2'}
VariableDescriptions : 1x2 homogeneous cell
VariableUnits : 1x2 homogeneous cell
VariableContinuity : 1x2 matlab.internal.coder.tabular.Continuity
StartTime : 1x1 matlab.coder.type.DurationType
SampleRate : 1x1 double
TimeStep : 1x1 matlab.coder.type.DurationTypeSee Also
timetable | coder.Constant | coder.typeof | coder.newtype