Main Content

Type Editor

Create, modify, and manage types, such as bus objects

Description

The Type Editor lets you interactively create, modify, and manage types.

The supported types are:

The Sources pane provides available sources, which are the MATLAB® base workspace and open data dictionaries. The objects that you create are stored in the selected source. In the toolstrip, you can create or open a data dictionary. You can also import objects defined by a MAT file, function, or script into the base workspace.

The Contents pane provides an interactive table with information about the objects, such as hierarchy and properties. You can select which columns appear in the table by using the Columns list in the toolstrip. Use the table to:

  • Filter objects — Enter a universal filter or a column-specific filter.

  • Edit objects — Double-click a value in the table and enter a new value. When you enter a value that is not supported, a diagnostic message appears in this pane.

  • Batch edit objects — Select objects of the same type that you want to edit. Double-click a value of one of the selected objects and enter a new value. The new value applies to all selected objects.

  • Navigate among types — Right-click an object that references another object and select Go to. Alternatively, click an object to highlight its referenced object. Use this navigation to bring you to the editable instance of a bus object and its elements.

  • Reorder bus element objects — Drag the bus element objects to a new position or use the Move Up and Move Down buttons in the toolstrip.

  • Cut, copy, and paste objects — Use keyboard shortcuts or the corresponding buttons in the toolstrip.

  • Delete objects — Press the Delete key or click the Delete button in the toolstrip. When you delete a bus object, you also delete the bus element objects it contains. Update any blocks that specify the deleted object. To find where a bus object is used in a model, see Finding Blocks That Use a Specific Variable.

Note

Changes that create, reorder, or delete objects take effect immediately in the base workspace. The Contents pane of the Type Editor does not support undo or redo actions.

The Property Inspector pane lets you focus on one object at a time and edit the object properties. When you enter a value that is not supported, a diagnostic message appears in this pane. To undo or redo a change, right-click the corresponding box. Then, select Undo or Redo.

The Type Editor can export object definitions to a MAT file (.mat) or function (.m). It can also create a MATLAB structure or Simulink.Parameter object from a Simulink.Bus object. You can find these actions in the Share section of the toolstrip.

Open the Type Editor

  • Simulink® Toolstrip: On the Modeling tab, in the Design gallery, click Type Editor.

  • MATLAB Command Window: Enter typeeditor.

  • Model Explorer: In a bus object dialog box, click Launch Type Editor.

  • MATLAB Workspace: Double-click a bus object, alias type, or value type.

Examples

expand all

Suppose you want to define an interface for a model with a Simulink.Bus object. For this example, the interface receives signals named sine, chirp, constant, pulse, and saw. You want the interface to group all the signals. Within that group, you want the interface to group the sinusoidal and nonsinusoidal signals.

You can create the objects in the base workspace or a data dictionary. In the Sources pane, select the location to contain the new objects.

  • To create a data dictionary, in the Type Editor toolstrip, click New. In the dialog box, specify a name for the data dictionary. Then, click Save.

  • To open a data dictionary, in the Type Editor toolstrip, click Open. In the dialog box, specify the data dictionary that you want to open. Then, click Open.

Create three Simulink.Bus objects.

  1. In the toolstrip, in the Add gallery, click Bus three times to create three Bus objects.

  2. Name the objects interface, sinusoidal, and nonsinusoidal. Double-click each object name in the table and enter the new name, or use the Property Inspector pane.

Add Simulink.BusElement objects to the Bus objects.

  1. Select the object named interface, and add three BusElement objects to it. In the toolstrip, click Bus Element three times.

  2. Name the elements constant, sinusoidal_bus, and nonsinusoidal_bus. Double-click each object name in the table and enter the new name or use the Property Inspector pane.

  3. Similarly, select the sinusoidal bus object and add two elements to it named sine and chirp.

  4. Select the nonsinusoidal bus object and add two elements to it named pulse and saw.

Any element in a bus can be another bus, which can in turn contain subordinate buses, to any depth. To mimic this bus hierarchy, a bus-element object can specify a bus object data type.

Nest the Bus objects named sinusoidal and nonsinusoidal in the Bus object named interface.

  1. For the object named sinusoidal_bus, set DataType to Bus: sinusoidal.

  2. For the object named nonsinusoidal_bus, set DataType to Bus: nonsinusoidal.

The object named interface now matches the desired hierarchy for the component interface. To specify the object at a component interface, you can specify it as the data type of In Bus Element, Inport, Out Bus Element, and Outport blocks.

In the Sources pane, select the location to contain the new objects.

You can create Simulink.AliasType, Simulink.NumericType, and Simulink.ValueType objects in the base workspace or a data dictionary. You can create Simulink.data.dictionary.EnumTypeDefinition objects only in a data dictionary.

  • To create a data dictionary, in the Type Editor toolstrip, click New. In the dialog box, specify a name for the data dictionary. Then, click Save.

  • To open a data dictionary, in the Type Editor toolstrip, click Open. In the dialog box, specify the data dictionary that you want to open. Then, click Open.

In the Type Editor toolstrip, in the Add gallery, select one of these options:

  • Alias Type — Create a Simulink.AliasType object.

  • Numeric Type — Create a Simulink.NumericType object.

  • Value Type — Create a Simulink.ValueType object.

  • Enum Type — Create a Simulink.data.dictionary.EnumTypeDefinition object.

The new object appears in the Contents pane.

You can use the Type Editor to modify objects in the base workspace and data dictionaries.

To edit one or more objects of the same type in the Type Editor:

  1. Select the objects that you want to update.

    • To select multiple noncontiguous objects, hold Ctrl and select each element.

    • To select multiple contiguous objects, hold Shift and select the first and last element.

    • To select all objects, first select one object. Then, press Ctrl+A.

  2. In the Contents pane, double-click the property value that you want to change for all the selected objects of the same type. Then, enter the new value.

    When you commit the new value, the change applies to all the selected objects that are the same type of object.

You can also edit one object at a time in the Property Inspector pane. Some object properties are available only in the Property Inspector pane.

For a bus object, edit the properties of the bus object and its elements at the top level, not where the bus object is specified as a data type. Right-click the dimmed object and select Go to to bring you to the editable instance of the object.

To reorder bus object elements, select and drag the elements to a new position or use the Move Up and Move Down buttons in the toolstrip.

You can edit contents in the filtered view just like the unfiltered view. Elements that no longer match the filter disappear from the table. Conversely, if some activity outside the Type Editor changes a filtered object so that it passes the current filter, the object immediately becomes visible.

Operations affect only the available objects. An object that a filter hides is unaffected by the operation. To act on all available objects, clear the filter.

When you create or modify objects in the base workspace or a data dictionary, save the objects for future use. If blocks specify these objects, the objects are required for simulation.

The Type Editor can save objects in a MAT file (.mat), MATLAB function (.m), or data dictionary (.sldd).

To save the objects that are in the base workspace:

  1. In the Sources pane, select the base workspace.

  2. In the toolstrip, click the Export button arrow. Then, select an option, which creates a MAT file or MATLAB function.

    For MATLAB functions, you have the option to save the objects in a compressed cell format or a more readable object format.

  3. In the Export dialog box, specify the file name, then click Save.

Alternatively, cut or copy the objects from the base workspace. Then, paste them in a data dictionary.

To save the objects that are in a data dictionary:

  1. In the Sources pane, select the modified data dictionary.

  2. In the toolstrip, click Save. Alternatively, right-click the data dictionary and select Save changes.

You can use the Type Editor to manage objects from multiple sources.

You can import objects from a function, script, or MAT file.

  1. In the toolstrip, click the Import button arrow, then select one of the options.

  2. In the Import into Base Workspace dialog box, select the file that defines the objects and click Open.

The import loads the complete contents of the file, not just the objects. The table displays the available objects in alphabetical order.

You can also open a data dictionary to manage its objects.

  1. In the toolstrip, click Open.

  2. In the Open dialog box, select the data dictionary that defines the objects and click Open.

Use filters to quickly find objects by name or property value. The filter can be a search term or regular expression. For information about regular expressions, see Regular Expressions.

To quickly find objects with a double data type, type double in either the Filter contents box or the Filter by DataType box that appears when you pause on the DataType column heading and click the button that appears. As you type, the table updates dynamically to show only the objects whose names or property values match the filter and their parents. The comparison is not case-sensitive.

You can use the Type Editor to create MATLAB structures for initialization.

Suppose you have a Simulink.Bus object named MyData that contains two elements named temperature and pressure.

  • temperature — Signal with a data type of int16

  • pressure — Nested array of buses with a data type of Bus: PressureBus and dimensions specified as [1 3]

The nested Bus object named PressureBus has two elements named s1 and s2.

MyData bus object in the Type Editor

Select the Bus object named MyData. Then, in the toolstrip, click MATLAB Structure.

Specify a name and location for the new MATLAB structure.

The MATLAB structure specifies an initial condition of 0 for each element.

MyData_MATLABStruct = struct;
MyData_MATLABStruct.temperature = int16(0);
MyData_MATLABStruct.pressure = struct;
MyData_MATLABStruct.pressure(1).s1 = 0;
MyData_MATLABStruct.pressure(1).s2 = 0;
MyData_MATLABStruct.pressure(2).s1 = 0;
MyData_MATLABStruct.pressure(2).s2 = 0;
MyData_MATLABStruct.pressure(3).s1 = 0;
MyData_MATLABStruct.pressure(3).s2 = 0;

Optionally, change the initial conditions of the structure elements.

Use the MATLAB structure to specify the Initial condition parameter of a block such as a Unit Delay block.

To create a MATLAB structure for a top-level Bus object that defines an array of buses, use the Simulink.Bus.createMATLABStruct function.

Tips

  • In the Contents pane, display only the columns that are relevant to you. For example, if your focus is simulation, in the Type Editor toolstrip, in the View section, change the column display from All to Value. If your focus is code generation, change the column display to Code. Alternatively, individually select which table columns appear with the Columns list.

  • A bus object cannot directly or indirectly reference itself. If you define a circular structure, the Type Editor keeps the original data type of the element that would have completed the circle.

  • When you have a model that creates a bus with a Bus Creator block, you can use the Simulink.Bus.createObject function to create the corresponding objects instead of creating each Simulink.Bus and Simulink.BusElement object individually.

Version History

Introduced before R2006a

expand all