Main Content

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 thetimetablefunction. For example, suppose the input arguments to your MATLAB®function are three arrays that have the same number of rows (A,B, andC), adatetimeordurationvector 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 thearray2timetableandtable2timetablefunctions. For example, you can convert an inputM-by-Nmatrix to a timetable, where each column of the matrix becomes a variable in the timetable. Assign row times by using adurationvector.

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 thedatetimeordurationdata 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=to:

  • Delete a variable or a row.

  • Add a variable or a row.

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 thetimerangeorwithtolfunctions.

Code generation supports:

  • Timetable indexing with smooth parentheses, ().

  • Content indexing with curly braces, {}.

  • Dot notation to access a timetable variable.

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.

  • For vertical concatenation, timetables must have variables that have the same names in the same order.

  • For horizontal concatenation, timetables must have the same number of rows. They also must have the same row times in the same order.

MATLABToolbox Functions That Support Timetables

For code generation, you can use timetables with these MATLAB toolbox functions:

Related Topics