Code Generation for Timetables
The timetable data type is a data type suitable for tabular data with
time-stamped rows. Like tables, timetables consist of rows and column-oriented variables. Each
variable in a timetable can have a different data type and a different size with one
restriction: each variable must have the same number of rows.
The row times of a timetable are time values that label the rows. You
can index into a timetable by row time and variable. To index into a timetable, use smooth
parentheses () to return a subtable or curly braces {}
to extract the contents. You can refer to variables and to the vector of row times by their
names. For more information, see Timetables.
When you use timetables with code generation, adhere to these restrictions.
Define Timetables for Code Generation
To define a timetable in MATLAB® code for code generation, use the timetable function. Alternatively, you can use the array2timetable and table2timetable function to convert arrays and
tables to timetables. For code generation, you must supply the "RowTimes"
and "VariableNames" name-value arguments when you create a timetable.
Timetable variable names do not have to be valid MATLAB identifiers. Variable names can include any
ASCII characters (such as commas, dashes, and space characters). Row times must be either
datetime or duration values.
For example, suppose A, B, and
C are 10-by-1 arrays of doubles, vnames is a cell
array of column names, and rtimes is a vector of
datetime values. You can generate code for a function that creates a
timetable using these arrays as timetable variables.
function TT = foo(A,B,C,D,vnames) %#codegen TT = timetable(A,B,C,'RowTimes',rtimes,'VariableNames',vnames); end
Allowed Operations on Timetables
For code generation, you are restricted to the operations on timetables listed in this table.
| Operation | Example | Notes |
|---|---|---|
Assignment operator: |
TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames); TT{:,1} = X; | Code generation does not support using the assignment operator
|
Indexing operation |
D = seconds(1:10); TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames); TT(seconds(3:7),1:3); | Code generation supports indexing by position, variable or row time,
and logical indexing. Also, you can index using objects created by using the
Code generation supports:
|
Concatenation |
TT1 = timetable(A,B,C,'RowTimes',D1,'VariableNames',vnames); TT2 = timetable(D,E,F,'RowTimes',D2,'VariableNames',vnames); TT = [TT1 ; TT2]; | Code generation supports timetable concatenation.
|
MATLAB Toolbox Functions That Support Timetables
For code generation, you can use timetables with these MATLAB toolbox functions: