C/C++ source code includes type declarations for all variables. MATLAB® code does not include explicit type declarations. To allow the generation of C/C++ code with specific types, you must specify the properties (class, size, and complexity) of all input variables to the MATLAB entry-point functions during C/C++ or MEX code generation. An entry-point function is a top-level MATLAB function from which you generate code. The code generator uses these input properties to determine the properties of all variables in the generated code. Different input type specifications can cause the same MATLAB code to produce different versions of the generated code.
When you generate C/C++ or MEX code at the command line, one of the
ways to specify the properties of an input argument is by using a
coder.Type object that contains information about class,
size, and complexity (and sometimes other properties) of the argument. You can create and
coder.Type objects programmatically at the command line, or
interactively by using the Coder Type Editor.
To create and edit composite types such as structures and cell arrays, or types that
have many customizable parameters such as
embedded.fi, use the Coder
Type Editor. Examples of such types are shown later in this topic.
To launch the Coder Type Editor, do one of the following:
Launch an empty type editor by using the
Open the type editor pre-populated with
corresponding to the workspace variables
var3 by typing:
coderTypeEditor var1 var2 var3
already exists in your base MATLAB workspace:
myType in the workspace.
myType at the command line and click
the Edit Type Object link that appears at the
end of the display.
Use this command at the MATLAB command line:
By using the toolstrip buttons in the type editor, you can perform these actions:
Create a new type by clicking New Type and specifying
the type, size, complexity, and other properties of the
Convert an existing variable to a type by clicking From Variable and specifying a variable that already exists in the base workspace.
Create a new type from an example value by clicking From
Example and entering MATLAB code that the software converts to a
coder.Type objects from the base workspace to the
Type Browser pane of the type editor by clicking
Edit an existing type by selecting it in the Type Browser and modifying its properties.
coder.Type objects in the type editor by clicking
Remove a selected type from Type Browser by clicking
Delete. Alternatively, remove
all types from the Type
Browser by clicking Delete > Delete all. Deleting a
coder.Type object from the
Type Browser does not delete the object from the
base MATLAB workspace.
Export a MATLAB script that contains the code to recreate all the types by clicking Share > MATLAB Script. Or, create a MAT file that contains all the types by clicking Share > MAT File.
Undo and redo your last action in the type editor by using the buttons.
These are some additional actions that you can perform in the Coder Type Editor:
In both the Type Browser pane and the Type Properties pane, copy a type object and paste it either as a new type or a field of an existing structure type. You can also copy the properties of one existing type into another existing type.
Change the order of fields of a structure type. View the type in the properties pane and use drag-and-drop action.
The Type Browser pane shows the name, class, and size of the
coder.Type objects that are currently loaded in the type editor.
For composite types such as structures, cell arrays, or classes, you can expand the
display of the
code.Type object in the Type Browser
pane. The expanded view shows the name, class, and complexity of the individual fields
or properties of the composite type.
|expander||The type has fields or properties that you can see by clicking the expander.|
|Homogeneous cell array (all elements have the same properties).|
|nth element of a heterogeneous cell array.|
|Variable-size dimension with an upper bound of n.|
|Variable-size dimension that is unbounded.|
The type properties pane displays the class (data type), size, and other properties of
coder.Type object that is currently selected in the Type
Browser. For composite types such as structures and classes, this pane
also shows the name, class, and size of each constituent field or property.
To edit the name, class, and size of a field in place, double-click the item.
Alternatively, click a field. The view in the type editor pane changes to display the properties of that field. Edit name, class(data type), size, or other properties in the pane.
The breadcrumb shows the nested path to the field that is currently open in the type properties pane. Click a field in the breadcrumb to display it in the pane. You can also edit the name of a type directly in the breadcrumb.
The MATLAB Code pane displays the MATLAB script that creates the
coder.Type object that is currently
selected in the Type Browser. To automate the creation of this
type, copy this script and include it in your build script.