When you create timetables in MATLAB® code that you intend for code generation, you must create them by using the
array2timetable
, table2timetable
, or timetable
functions. For more information, see Timetables (MATLAB).
For timetables, code generation has these limitations:
The row times must have the duration
data type. Row times cannot
have the datetime
data type.
The name of the first dimension of a timetable is always 'Time'
.
The name of the first dimension is also the name of the vector of row times, which you can
refer to using dot notation.
You must specify variables names by using the 'VariableNames'
name-value pair argument when creating timetables from input arrays by using the
timetable
or array2timetable
functions.
You do not have to specify the 'VariableNames'
argument when you
preallocate a timetable by using the timetable
function and the
'Size'
name-value pair argument.
Timetable variable names must be valid MATLAB identifiers. Variable names must start with a letter and can include only letters, digits, and underscores.
After you create a timetable, you cannot change the VariableNames
,
DimensionNames
, or UserData
properties.
When you create a timetable, you can specify the 'VariableNames'
and 'RowTimes'
input arguments to set the properties having those
names.
To create a regular timetable when specifying the 'SampleRate'
,
'StartTime'
, or 'TimeStep'
name-value pair
arguments, first use the coder.Constant
function to make the values
constant. If you do not make them constant, then the row times are considered to be
irregular.
Also, if you create an irregular timetable, then it remains irregular even if you set its sample rate or time step.
If you create a regular timetable, and you attempt to set irregular row times, then an error is produced.
To index into a timetable by using variables names, first use the
coder.Constant
function to make the timetable constant.
By default, timetables that you pass into generated code as input arguments are not constant. Even their variables and row times are not constant. If a timetable is not constant, then an indexing operation that uses variables produces an error. You can index into the variables of a timetable by using numeric or logical indices even if the timetable is not constant.
To pass timetable indices into generated code as input arguments, first use the
coder.Constant
function to make the indices into the second
dimension of the timetable constant. If indices into the second dimension are not
constant, then indexing into variables produces an error.
If you index into a timetable by using duration
values, or an
object produced by the timerange
or withtol
functions, then the output is always nonconstant with a variable number of rows.
If you index into a regular timetable by using duration
values, or
an object produced by the timerange
or withtol
functions, then the output is always considered to be irregular.
You cannot add custom metadata to a timetable. The addprop
and
rmprop
functions are not supported.
You cannot change the size of a timetable by assignments. For example, this call to add a new row produces an error.
function TT = foo() %#codegen TT = timetable((1:3)',(1:3)','RowTimes',seconds([0,5,10]),... 'VariableNames',{'Var1','Var2'}); TT{4,:} = [5,5]; end
Deleting a row or a variable by assignment also produces an error.
You cannot add a new row by using a new row time in an assignment. For example, this call to add a new row by using a new row time instead of a numeric index does not produce an error, but also does not add the new row.
function TT = foo() %#codegen TT = timetable((1:3)',(1:3)','RowTimes',seconds([0,5,10]),... 'VariableNames',{'Var1','Var2'}); TT{seconds(15),:} = [5,5]; end
When you preallocate a timetable, 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 |
| Double- or single-precision |
| Signed 8-, 16-, 32-, or 64-bit integer
|
| Unsigned 8-, 16-, 32-, or 64-bit integer
|
|
|
|
|
|
|
|
|
If you specify 'char'
as a data type, then
timetable
preallocates the corresponding variable as a cell array
of character vectors, not as a character array. The best practice is to avoid creating
timetable variables that are character arrays.
When you vertically concatenate timetables, 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 timetables.
When you horizontally concatenate timetables, they must have the same row times in the same order. In MATLAB, the row times must be the same but can be in different orders in the timetables.
If two timetables have variables that are N-D cell arrays, then you cannot vertically concatenate the timetables.
You cannot use curly braces to extract data from multiple timetable variables that are N-D cell arrays because this operation is horizontal concatenation.
Limitations that apply to classes also apply to timetables. For more information, see MATLAB Classes Definition for Code Generation.
array2timetable
| table2timetable
| timetable