Main Content

Create and Edit Input Types by Using the Coder Type Editor

Fixed-Point Designer™ must determine the properties of all variables in the MATLAB® files at compile time. To infer variable properties in MATLAB files, Fixed-Point Designer must be able to identify the properties if the inputs to the top-level MATLAB functions, also known as entry-point functions. Therefore, if your entry-point function has inputs, you must specify the properties of these inputs.

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:

    coderTypeEditor
  • Open the type editor pre-populated with coder.Type objects corresponding to the workspace variables var1, var2, and var3 by typing:

    coderTypeEditor var1 var2 var3
  • Open a coder.Type object myType 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:

      open myType

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 the Type Browser pane of the type editor by clicking Load 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 clicking Save All.

  • 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 Undo and redo 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 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.

Type Browser pane, showing the type objects aType, bType, and cType. bType and cType are composite objects.

Visual Indicators on the Type Browser

IndicatorDescription
expanderThe 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.
:nVariable-size dimension with an upper bound of n.
:infVariable-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.

Close-up of the "Fields" section of the Type Properties pane, showing a the f1 field selected for editing

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.

Pane displaying the properties of the f1 field of the bType variable

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.

Variable bType selected for editing

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.

MATLAB code pane showing a script that can be used to recreate fields f1, f2, and f2 of variable bType

See Also

| |

Related Topics