Type Editor - Create, modify, and manage types, such as bus objects - MATLAB (original) (raw)

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

Renamed from Bus Editor in R2022b

Description

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

Supported types include:

The Type Editor has two variations:

The Type Editor has an interactive table that provides information about the objects, such as hierarchy and properties.

To select which columns appear in the table, change the view. Alternatively, right-click a column title and select the desired columns. Supported views include:

Use the table to:

Note

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 interactive table does not support undo or redo actions.

To focus on one object at a time and edit the object properties, use the Property Inspector. When you select an object in the Type Editor, the Property Inspector shows the properties of that object. In the Property Inspector, when you enter a value that is not supported by a property, a diagnostic message appears. To undo or redo a change, right-click the corresponding box. Then, selectUndo or Redo.

How you access the Property Inspector depends on the variation of the Type Editor that you have open.

The Type Editor can export object definitions to a MAT file (.mat) or function (.m).

To create a MATLAB® structure or Simulink.Parameter object from aSimulink.Bus object, use the standalone Type Editor.

Standalone Type Editor

Open the Type Editor

Open the standalone Type Editor.

Open the docked Type Editor.

Examples

expand all

You can create and edit types in multiple external data sources with theType Editor.

In the standalone Type Editor, use theSources pane to switch among external data sources, such as the base workspace and a data dictionary.

To open a data dictionary in the standalone Type Editor:

  1. In the Type Editor toolstrip, clickOpen for an existing dictionary orNew for a new dictionary.
  2. In the dialog box that opens, specify the data dictionary that you want to use.
  3. Click Open orSave, depending on whether you are opening an existing or new dictionary.

To add or remove external data sources for your model via the docked Type Editor:

  1. Click Link external sources. Alternatively, click the Save or link external sources button arrow. Then, selectLink.
  2. In the Model Properties dialog box that opens, configure the external data sources for your model. For example, add or remove a data dictionary and toggle whether your model has access to the base workspace. For more information, see Migrate Models to Use Simulink Data Dictionary.

How you create types in the Type Editor depends on whether you open the Type Editor in the context of a model window or as a standalone window.

In the standalone Type Editor:

  1. Click the down arrow on the far right of theAdd section to expand the gallery.
  2. Select the type you want to create.
    • Bus — Create aSimulink.Bus object.
    • Connection Bus — Create aSimulink.ConnectionBus object.
    • Alias Type — Create aSimulink.AliasType object.
    • Value Type — Create aSimulink.ValueType object.
    • Numeric Type — Create aSimulink.NumericType object.
    • Enum Type (data dictionary only) — Create aSimulink.data.dictionary.EnumTypeDefinition object.
      Tip
      Toggle the Add to favorites or Remove from favorites button to promote your most commonly used types to the top of the gallery.
  3. To add elements to bus objects, select the bus object. Then, in the gallery, click the appropriate button once for each element you want to add.
    • Bus Element — Create aSimulink.BusElement object in aSimulink.Bus object.
    • Connection Bus Element — Create a Simulink.ConnectionElement object in a Simulink.ConnectionBus object.

The new type appears in the interactive table.

In the docked Type Editor:

  1. Click the Create types button arrow.
  2. Select the type you want to create.
    • Bus object — Create aSimulink.Bus object.
    • Connection bus object — Create a Simulink.ConnectionBus object.
    • Alias type — Create aSimulink.AliasType object.
    • Value type — Create aSimulink.ValueType object.
    • Numeric type — Create aSimulink.NumericType object.
    • Enumerated type (data dictionary only) — Create aSimulink.data.dictionary.EnumTypeDefinition object.
  3. To add elements to bus objects, select the object. Then, click Create elements once for each element you want to add.

You can import types from a function, script, or MAT file into the Type Editor.

  1. How you import types in the Type Editor depends on whether you open the Type Editor in the context of a model window or as a standalone window.
    • Standalone Type Editor — In theType Editor toolstrip, click theImport button arrow.
    • Docked Type Editor — Click the Import types into base workspace button arrow.
  2. Select one of the options.
    • MAT File — Import types from a MAT file (.mat).
    • Function or Script — Import types from a MATLAB function or script (.m).
  3. In the Import into Base Workspace dialog box, select the file that defines the types.
  4. Click Open.

The import loads the complete contents of the file, not just the types. The table displays the available types.

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.

For example, to quickly find objects with a double data type, type double in either:

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 modify types in external data sources, such as the base workspace and data dictionaries.

To edit one or more types in the Type Editor, use the interactive table.

  1. Select the types that you want to update.
    • To select multiple noncontiguous types, holdCtrl and select each element.
    • To select multiple contiguous types, holdShift and select the first and last element.
    • To select all types, first select one type. Then, press Ctrl+A.
  2. Double-click the property value that you want to change for all the selected types. Then, enter the new value.
    When you commit the new value, the change applies to all the selected types that are of the same base type as the type you changed, for example, all the Simulink.Bus objects or all the Simulink.ValueType objects.

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 type so that the type passes the current filter, the type immediately becomes visible.

Operations affect only the available types. A type that a filter hides is unaffected by the operation. To act on all available types, clear the filter.

To edit one type at a time, use the Property Inspector. Some properties are available only in the Property Inspector.

For bus types:

While the Type Editor displays service interfaces, you must use the Architectural Data Editor or Interface Editor (System Composer) to edit their properties. (since R2023b)

When you create or modify types, save the types for future use. If blocks specify these types, the types are required for simulation.

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

To save all the types that are in the base workspace:

  1. How you save types in the Type Editor depends on whether you open the Type Editor in the context of a model window or as a standalone window.
    • Standalone Type Editor — In theType Editor toolstrip, click theExport button arrow.
    • Docked Type Editor — Click the Export types to MAT file (.mat) or function (.m) button arrow.
  2. Select one of the options.
    • MAT File — Export types to a MAT file (.mat).
    • Function (Cell Format) — Export types to a MATLAB function that uses the more compact cell format.
    • Function (Object Format) — Export types to a MATLAB function that uses the more readable object format.
  3. In the Export dialog box, specify the file name. Then, clickSave.

To save a subset of the types that are in the base workspace:

  1. Select the types to save.
  2. Right-click one of the selected types. Then, click one of these options.
    • Export to File — Export the selected types to a file.
    • Export with Dependencies to File — Export the selected types and any types they reference to a file.
  3. Select one of the file options.
    • MAT File — Export types to a MAT file (.mat).
    • Function (Cell Format) — Export types to a MATLAB function that uses the more compact cell format.
    • Function (Object Format) — Export types to a MATLAB function that uses the more readable object format.
  4. In the Export dialog box, specify the file name. Then, clickSave.

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

To save the objects in a data dictionary, your action depends on the variation of theType Editor that you have open.

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

Create three bus objects.

  1. How you create bus objects in the Type Editor depends on whether you open the Type Editor in the context of a model window or as a standalone window.
    • Standalone Type Editor — In theType Editor toolstrip, in theAdd gallery, clickBus three times.
    • Docked Type Editor — Click Create types three times.
  2. Name the objects interface,sinusoidal, andnonsinusoidal. Double-click each object name in the table and enter the new name, or use the Property Inspector.

Add Simulink.BusElement objects to theSimulink.Bus objects.

  1. Select the object named interface.
  2. How you add elements to bus objects in the Type Editor varies.
    • Standalone Type Editor — In theType Editor toolstrip, in theAdd gallery, clickBus Element three times.
    • Docked Type Editor — Click Create elements three times.
  3. Name the elements constant,sinusoidal_bus, andnonsinusoidal_bus. Double-click each object name in the table and enter the new name, or use the Property Inspector.
  4. Similarly, select the sinusoidal bus object and add two elements to it named sine andchirp.
  5. Similarly, 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 andnonsinusoidal in the bus object namedinterface.

  1. For the object named sinusoidal_bus, setDataType tosinusoidal or Bus: sinusoidal.
  2. For the object named nonsinusoidal_bus, setDataType tononsinusoidal or Bus: nonsinusoidal.

When you set the data type of a Simulink.BusElement object to a Simulink.Bus object, theBus: prefix is optional.

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.

Since R2023b

When you open the Type Editor in the context of a model, the Type Editor displays the types used by a model. The Type Editor helps you find where these types are used in the model by highlighting the corresponding blocks and ports for a selected type.

Open the ComponentBasedModeling project. Optionally, compile the model that opens. To compile the model, on the Modeling tab of the Simulink Toolstrip, click Update Model or Run. Compiling the model updates the line styles, which you can use to visually identify buses.

ComponentBasedModeling block diagram with subsystems connected by buses

To view the types that the model uses, on the Modeling tab, in the Design gallery, click Type Editor. Alternatively, press Ctrl+Shift+P.

To expand an external data source, click the arrow next to the data source name.

Docked Type Editor with bus objects in a data dictionary

The top model in the model hierarchy has access to three external data sources:

The controller interface uses Simulink.Bus objects named Controls, Goals, and Sensors.

To display where the model uses a bus object, click the bus object in the Type Editor. For example, click Sensors.

In the Type Editor, Sensors is selected. In the block diagram, the Controller subsystem is highlighted.

The block diagram highlights the Subsystem block named Controller because the subsystem uses the Sensors bus object.

Double-click the Controller subsystem to open it.

Controller subsystem block diagram and the docked Type Editor

A subsystem has access to the same external data sources as its parent model.

In the Type Editor, click Sensors.

In the Type Editor, Sensors is selected. In the block diagram, an OutBus and sensor port are highlighted.

The block diagram highlights two ports because they use the Sensors bus object.

Double-click the Controller model to open it.

Controller referenced model and docked Type Editor

The referenced model named ComponentController has access to two external data sources:

The ComponentBasedModelingData dictionary no longer appears in the Type Editor.

In the Type Editor, click Sensors.

In the Type Editor, Sensors is selected. In the block diagram, nothing is highlighted.

The block diagram does not highlight blocks or ports because the top-level bus object does not correspond with a visible block or port in the block diagram.

In the Type Editor, expand Sensors. Then, click one of its elements. For example, click the element named x1.

In the Type Editor, x1 is selected. In the block diagram, two In Bus Element blocks labeled sensor.x1 are highlighted.

The block diagram highlights the In Bus Element blocks that select the element named x1 from the Sensors bus object.

Since R2023b

When you open the Type Editor in the context of a model, you can use the Type Editor to assign the selected type to a block.

Open the ComponentBasedModeling project. Optionally, compile the model that opens. To compile the model, on the Modeling tab of the Simulink Toolstrip, click Update Model or Run. Compiling the model updates the line styles, which you can use to visually identify buses.

ComponentBasedModeling block diagram with subsystems connected by buses

To open the Type Editor, on the Modeling tab, in the Design gallery, click Type Editor. Alternatively, press Ctrl+Shift+P. To expand an external data source, click the arrow next to the data source name.

Docked Type Editor with bus objects in a data dictionary

Suppose you want to define the interface that provides the sensor data in the top model. You can use the Simulink.Bus object named Sensors to define this interface.

In the Type Editor, click Sensors.

In the Type Editor, Sensors is selected. In the block diagram, the Controller subsystem is highlighted.

The sensor port of the Subsystem block named Plant provides the sensor data, but the port is not highlighted because it does not use the Sensors bus object.

On the Subsystem block named Plant, select the sensor port.

Highlighted sensor port on Plant subsystem

In the Type Editor, right-click Sensors. Then, select Assign type to selected blocks and ports.

In the Type Editor, Sensors is selected. In the block diagram, the Controller subsystem and sensor port are highlighted.

The sensor port is now highlighted because it uses the Sensors bus object.

Double-click the Subsystem block named Plant.

Plant subsystem block diagram with In Bus Element and Out Bus Element blocks

Two Out Bus Element blocks correspond with the sensor port.

Double-click either of these Out Bus Element blocks.

Bus hierarchy with top-level sensor bus defined by Bus: Sensors

The Out Bus Element blocks that create the sensor interface are now defined by the Sensors bus object.

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

Suppose you have a Simulink.Bus object namedMyData that contains two elements namedtemperature and pressure.

The nested Bus object namedPressureBus has two elements nameds1 and s2.

MyData bus object in the Type Editor

Right-click the Simulink.Bus object namedMyData. Then, select Create MATLAB Structure. Alternatively, in the standalone Type Editor, select the Simulink.Bus object. Then, in the Type Editor toolstrip, click MATLAB Structure.

Specify a name and location for the new MATLAB structure.

The MATLAB structure specifies an initial condition of0 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 Simulink.Bus object that defines an array of buses, use the Simulink.Bus.createMATLABStruct function.

Tips

Version History

Introduced before R2006a

expand all

When the Type Editor is docked in a model window, the Type Editor displays the available types for the model grouped by source.

Docked Type Editor displaying types in a data dictionary and the base workspace

To add or remove external data sources, click Link external sources. Alternatively, click the Save or link external sources button arrow. Then, selectLink.

When you open the Type Editor from a model, the Type Editor is docked as a pane in the model window.

Docked Type Editor with simplified buttons and layout

This integration lets you view where a type is used in your model. For example, you can click a type in the docked Type Editor to highlight the blocks that use the type. For more information, see View Types in Models Using Docked Type Editor.

To open the Type Editor in a standalone window, click Open standalone Type Editor.

The Type Editor displays service interfaces from data dictionaries. The service interfaces are for System Composer™ and AUTOSAR Blockset software architecture models. To edit the service interfaces, use theArchitectural Data Editor or Interface Editor (System Composer).

To reflect the support for value types, alias types, numeric types, and enumerations in addition to bus objects, the Bus Editor is now called the Type Editor.

To reflect the name change, the buseditor function is replaced by the typeeditor function. The behavior remains the same.

There are no plans to remove support for the buseditor function.

The Bus Editor loads faster and has an updated interface for creating, modifying, and managing bus objects. However, the Bus Editor no longer supports custom import and export functions.

Remove the cm.BusEditorCustomizer.importCallbackFcn andcm.BusEditorCustomizer.exportCallbackFcn registration functions from the sl_customization function. To eliminate both customizations in one operation for a customization manager object namedcm, use this command.

cm.BusEditorCustomizer.clear

For more information about customizations, see Register Customizations with Simulink.