Main Content

Define Timetable Inputs

You can define timetable inputs at the command line or in the MATLAB® Coder™ app. Programmatic specification of timetable input types by using preconditioning (assert statements) is not supported.

Define Timetable Inputs at the Command Line

Use one of these procedures:

Alternatively, if you have a test file that calls your entry-point function with example inputs, you can determine the input types by using coder.getArgTypes.

Provide an Example Timetable Input

Use the -args option:

TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames);
codegen myFunction -args {TT}

Provide a Timetable Type

To provide a type for a timetable to codegen:

  1. Define a timetable. For example:

    TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames);

  2. Create a type from T.

    t = coder.typeof(TT);
    

  3. Pass the type to codegen by using the -args option.

    codegen myFunction -args {t}
    

Provide a Constant Timetable Input

To specify that a timetable input is constant, use coder.Constant with the -args option:

TT = timetable(A,B,C,'RowTimes',D,'VariableNames',vnames);
codegen myFunction -args {coder.Constant(TT)}

Define Timetable Inputs in the MATLAB Coder App

Use one of these procedures:

Representation of Timetables

A coder type object for a timetable describes the object and its properties. Use coder.typeof or pass timetable as a string scalar to coder.newtype.

The coder type object displays a succinct description of the object properties while excluding internal state values. Nonconstant properties display their type and size, while constant properties display only their values. For example:

t = timetable((1:5)',(11:15)','SampleRate',1);
tType = coder.typeof(t)

The representation of variable t is stored in coder type object tType.

tType = 

   matlab.coder.type.RegularTimetableType
     5x2 timetable
	                Data : 1x2 homogeneous cell
	         Description : 1x0 char
	            UserData : 0x0 double
	      DimensionNames : {'Time'}    {'Variables'}
	       VariableNames : {'Var1'}    {'Var2'}
	VariableDescriptions : 1x2 homogeneous cell
	       VariableUnits : 1x2 homogeneous cell
	  VariableContinuity : 1x2 matlab.internal.coder.tabular.Continuity
	           StartTime : 1x1 matlab.coder.type.DurationType
	          SampleRate : 1x1 double
	            TimeStep : 1x1 matlab.coder.type.DurationType

Define a regular timetable by specifying the SampleRate or TimeStep. You can also define an irregular timetable by specifying the RowTimes. For example:

t1 = timetable((1:3),'RowTimes',seconds(1:3));
t1Type = coder.typeof(t)

The representation of irregular table t1 is stored in coder type object t1Type.

t1Type = 

   matlab.coder.type.TimetableType
     3x1 timetable
	                Data : 1x1 homogeneous cell
	         Description : 1x0 char
	            UserData : 0x0 double
	      DimensionNames : {'Time'}    {'Variables'}
	       VariableNames : {'Var1'}
	VariableDescriptions : 1x1 homogeneous cell
	       VariableUnits : 1x1 homogeneous cell
	  VariableContinuity : 1x1 matlab.internal.coder.tabular.Continuity
	            RowTimes : 3x1 matlab.coder.type.DurationType

If your workflow requires the legacy representation of coder type objects, use the getCoderType function on the variable that has the new representation of your class or object. See Legacy Representation of Coder Type Objects.

Resize Object Properties by Using coder.resize

You can resize most objects by using coder.resize. You can resize objects, its properties and create arrays within the properties.

For a timetable coder object, you can resize the object properties:

t = timetable((1:5)',(11:15)','SampleRate',1);
tType = coder.typeof(t);
tType.UserData = coder.resize(tType.UserData,[10 1],[1 0])

This code resizes the UserData property to be a :10x1 double property. The first dimension is upper-bound at10.

tType = 

   matlab.coder.type.RegularTimetableType
     5x2 timetable
	                Data : 1x2 homogeneous cell
	         Description : 1x0 char
	            UserData : :10x1 double
	      DimensionNames : {'Time'}    {'Variables'}
	       VariableNames : {'Var1'}    {'Var2'}
	VariableDescriptions : 1x2 homogeneous cell
	       VariableUnits : 1x2 homogeneous cell
	  VariableContinuity : 1x2 matlab.internal.coder.tabular.Continuity
	           StartTime : 1x1 matlab.coder.type.DurationType
	          SampleRate : 1x1 double
	            TimeStep : 1x1 matlab.coder.type.DurationType

You can also resize the object by using coder.resize. See Edit and Represent Coder Type Objects and Properties.

See Also

| |

Related Topics