Code Generation for Timetables
Thetimetable
数据类型是一种数据类型适合表格数据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.
Therow timesof 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, seeTimetables.
When you use timetables with code generation, adhere to these restrictions.
Define Timetables for Code Generation
For code generation, use thetimetable
function. For example, suppose the input arguments to your MATLAB®function are three arrays that have the same number of rows (A
,B
, andC
), adatetime
orduration
vector containing row times (D
), and a cell array that has variable names (vnames
). You can create a timetable that contains these arrays as timetable variables.
functionTT = foo(A,B,C,D,vnames)%#codegenTT = table(A,B,C,'RowTimes',D,'VariableNames',vnames);end
To convert arrays and tables to timetables, use thearray2timetable
andtable2timetable
functions. For example, you can convert an inputM
-by-N
matrix to a timetable, where each column of the matrix becomes a variable in the timetable. Assign row times by using aduration
vector.
functionTT = foo(A,D,vnames)%#codegenTT = array2timetable(A,'RowTimes',D,'VariableNames',vnames);end
For code generation, you must supply timetable variable names when you create a timetable. Timetable variable names do not have to be valid MATLAB identifiers. The names must be composed of ASCII characters, but can include any ASCII characters (such as commas, dashes, and space characters).
The row times can have either thedatetime
orduration
data type.
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; |
代码生成不支持金宝appusing 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.
|
MATLABToolbox Functions That Support Timetables
For code generation, you can use timetables with these MATLAB toolbox functions: