Main Content

Simulink.BusElement

Specify properties of elements of buses

Description

A Simulink.BusElement object is an element of a Simulink.Bus object that validates the properties of an element in a bus. When you simulate or update a model, Simulink® checks whether the properties specified by the BusElement object match the properties specified by the corresponding bus elements.

BusElement objects exist only within the Bus object. You can specify a Bus object, but not a BusElement object, as a data type.

To create and modify Bus and BusElement objects in the base workspace or a data dictionary, you can use the Bus Editor, Model Explorer, or MATLAB® commands. You cannot store Bus objects in model workspaces.

Creation

You can create a BusElement object in multiple ways.

  • To programmatically create a BusElement object, use the Simulink.BusElement function (described here).

  • To interactively create a BusElement object, use the Bus Editor or Model Explorer.

  • To create BusElement objects from blocks in a model, MATLAB data, and external C code, see Create Bus Objects Programmatically.

Description

example

be = Simulink.BusElement returns a BusElement object with default property values.

Properties

expand all

Name of element, specified as a character vector.

Note

To validate the properties of a signal against a BusElement object, the signal name must be a valid identifier that starts with an alphabetic character or underscore (_), followed by alphanumeric characters or underscores.

Data Types: char | string

Numeric type of the element, specified as 'real' or 'complex'.

Data Types: char | string

Dimensions of element, specified as a scalar or vector.

To use symbolic dimensions in generated code, see Implement Dimension Variants for Array Sizes in Generated Code (Embedded Coder).

Data Types: double

Data type of element, specified as a character vector or string scalar.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

You can specify any of these options:

  • Built-in Simulink data type — For example, specify 'single' or 'uint8'. See Data Types Supported by Simulink.

  • Fixed-point data type — Use the fixdt function. For example, specify 'fixdt(1,16,0)'.

  • Enumerated data type — Use the name of the type preceded by Enum:. For example, specify 'Enum: myEnumType'.

  • Bus data type — Use the name of the Simulink.Bus object preceded by Bus:. For example, specify 'Bus: myBusObject'.

  • Value type — Use the name of the Simulink.ValueType object preceded by ValueType:. For example, specify 'ValueType: windVelocity'.

  • Custom data type — Use a MATLAB expression that specifies the type. For example, you can specify a Simulink.NumericType object whose DataTypeMode property is set to a value other than 'Fixed-point: unspecified scaling'.

Specifying a Simulink.Bus object allows you to create Bus objects that specify hierarchical buses (that is, buses that contain other buses).

When you specify a Simulink.ValueType or Simulink.Bus object, the object defines more than the data type. The object also defines properties such as Min, Max, and Unit. The property values specified by the ValueType object override the corresponding property values specified by a block. For example, suppose a block sets Unit to ft/s. When the Data type of the block specifies a ValueType object that has m/s as its unit, the block uses m/s instead of ft/s.

Data Types: char | string

Minimum value of the element, specified as a scalar. This value must be a finite real double scalar or, if the element is a bus, the value must be empty, [].

Data Types: double

Maximum value of the element, specified as a scalar. This value must be a finite real double scalar or, if the element is a bus, the value must be empty, [].

Data Types: double

Specify how to handle size of element, specified as 'Fixed' or 'Variable'.

Data Types: char | string

Physical unit for expressing element, specified as a character vector.

For more information, see Unit Specification in Simulink Models.

Example: 'inches'

Data Types: char | string

Bus element description, specified as a character vector. Use the description to document information about the BusElement object, such as the kind of signal it applies to. This information does not affect Simulink processing.

Data Types: char | string

Examples

collapse all

Create a hierarchy of Bus objects using arrays. Array indexing lets you create and access multiple elements in an array. Dot notation lets you access property values.

Create two BusElement objects, named Chirp and Sine, in the base workspace.

elems(1) = Simulink.BusElement;
elems(1).Name = 'Chirp';

elems(2) = Simulink.BusElement;
elems(2).Name = 'Sine';

Create a Bus object, named NestedBus, that uses the elements defined in the elems array.

NestedBus = Simulink.Bus;
NestedBus.Elements = elems;

Create two more BusElement objects, named NestedBus and Step. To have NestedBus represent a Bus object, specify a Bus object data type.

clear elems

elems(1) = Simulink.BusElement;
elems(1).Name = 'NestedBus';
elems(1).DataType = 'Bus: NestedBus';

elems(2) = Simulink.BusElement;
elems(2).Name = 'Step';

Create the bus at the top of the bus hierarchy that uses the elements defined in the elems array.

TopBus = Simulink.Bus;
TopBus.Elements = elems;

You can view the created objects in the Bus Editor.

buseditor

Compatibility Considerations

expand all

Errors starting in R2020b

Not recommended starting in R2016b

Introduced before R2006a