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 (MATLAB).
When you use timetables with code generation, adhere to these restrictions.
For code generation, use the timetable
function. For example, suppose the
input arguments to your MATLAB® function are three arrays that have the same number of rows
(A
, B
, and C
), a
duration
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.
function TT = foo(A,B,C,D,vnames) %#codegen TT = table(A,B,C,'RowTimes',D,'VariableNames',vnames); end
To convert arrays and tables to timetables, use the array2timetable
and table2timetable
functions. For example, you can
convert an input M
-by-N
matrix to a timetable, where
each column of the matrix becomes a variable in the timetable. Assign row times by using a
duration
vector.
function TT = foo(A,D,vnames) %#codegen TT = array2timetable(A,'RowTimes',D,'VariableNames',vnames); end
For code generation, you must supply timetable variable names when you create a timetable.
Timetable variables must have one of these data types:
Numeric
Text, in a cell array of character vectors
logical
datetime
duration
categorical
The row times must have the duration
data type. Row times cannot have
the datetime
data type.
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
To index by using variables, first make input timetables
constant 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.
|
For code generation, you can use timetables with these MATLAB toolbox functions: