Create and Edit Input Types by Using the Coder Type Editor - MATLAB & Simulink (original) (raw)
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 edit coder.Type
objects programmatically at the command line, or interactively by using the Coder Type Editor.
For more information about creating coder.Type
objects at the command line, see coder.typeof and coder.newtype.
Note
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.
Open the Coder Type Editor
To open the Coder Type Editor, do one of the following:
- Open an empty type editor by using the coderTypeEditor command:
- Open the type editor pre-populated with
coder.Type
objects corresponding to the workspace variablesvar1
,var2
, andvar3
by typing:
coderTypeEditor var1 var2 var3 - Open a
coder.Type
objectmyType
that already exists in your base MATLAB workspace:- Double click
myType
in the workspace. - Display
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:
- Double click
Common Editor Actions
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
coder.Type
object. - 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
object. - Load all
coder.Type
objects from the base workspace to theType Browser pane of the type editor by clickingLoad All. - Edit an existing type by selecting it in the Type Browser and modifying its properties.
- Save all
coder.Type
objects in the type editor by clickingSave All. - Remove a selected type from Type Browser by clickingDelete. Alternatively, remove all types from the Type Browser by clicking Delete > . Deleting a
coder.Type
object from theType 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 > . Or, create a MAT file that contains all the types by clicking Share > .
- 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.
Type Browser Pane
The Type Browser pane shows the name, class, and size of thecoder.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.
Visual Indicators on the Type Browser
Indicator | Description |
---|---|
expander | The type has fields or properties that you can see by clicking the expander. |
{:} | Homogeneous cell array (all elements have the same properties). |
{n} | nth element of a heterogeneous cell array. |
:n | Variable-size dimension with an upper bound of n. |
:inf | Variable-size dimension that is unbounded. |
Type Properties Pane
The type properties pane displays the class (data type), size, and other properties of the 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.
MATLAB Code Pane
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.
See Also
coderTypeEditor | coder | coder.typeof | coder.newtype