Main Content

Bus Selector

Select elements from input bus

  • Bus Selector block

Libraries:
Simulink / Commonly Used Blocks
Simulink / Signal Routing
HDL Coder / Signal Routing

Description

The Bus Selector block extracts the elements you select by name from the input bus hierarchy. The block can output the selected elements separately or in a new virtual bus. When the block outputs the selected elements separately, each selected element corresponds to an output port. When the block outputs a new virtual bus, the block has one output port for the virtual bus that contains each selected element.

While multiple elements can have the same name in different locations in the bus hierarchy, each element has a unique fully qualified name that the Bus Selector block uses. For example, the top-level bus and a nested bus can both have an element named chirp. The fully qualified name for the element in the top-level bus is chirp. The fully qualified name for the element in the nested bus is nestedbus.chirp, where nestedbus is the name of the nested bus.

Tip

For buses at subsystem and model interfaces, use In Bus Element blocks instead of an Inport block with a Bus Selector block. In Bus Element blocks:

  • Reduce line complexity and clutter in a block diagram.

  • Allow you to more easily change the interface incrementally.

  • Allow access to a bus element closer to the point of usage, avoiding the use of a Bus Selector and Goto block configuration.

Examples

expand all

The Bus Selector block lets you extract elements from a bus by name.

Open and compile the example model named BusElementSelection. 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.

The output signal from a Bus Selector block connects to one of the three Out Bus Element blocks.

The Bus Creator blocks create a bus hierarchy from source signals.

  • The Bus Creator block named Bus Creator groups the signals named sine and chirp into a bus named sinusoidal.

  • The Bus Creator block named Bus Creator1 groups the signals named pulse and saw into a bus named nonsinusoidal.

  • The Bus Creator block named Bus Creator2 groups the two buses and the signal named constant into a bus named sources.

The Bus Selector block receives the bus named sources as input and returns the signal named chirp as output.

In this example, the Bus Selector block output connects to an Out Bus Element block. Two Out Bus Element blocks remain unconnected.

To add an output port to the Bus Selector block, click the output edge of the Bus Selector block.

Cursor on the edge of the block

Start typing the name of the element you want to select, for example, nonsinusoidal.

Menu that provides input elements with optional filtering

Use the arrow keys to select the element named nonsinusoidal. Then, press Enter. Alternatively, click the element name in the menu.

Connect the new port to an Out Bus Element block. Optionally, compile the model to display the bus line style for the selected bus.

The nonsinusoidal bus connects to the second Out Bus Element block.

To connect a block to a new output port on the Bus Selector block, drag an unconnected input port of the block to the output edge of the Bus Selector block.

For example, drag the input port of the remaining Out Bus Element block to the output edge of the Bus Selector block.

A line is dragged from the third Out Bus Element block to the output side of the Bus Selector block.

Start typing the name of the element you want to select, for example, saw.

Menu that provides input elements with optional filtering

Use the arrow keys to select the element named nonsinusoidal.saw. Then, press Enter. Alternatively, click the element name in the menu.

The saw signal connects to the third Out Bus Element block.

In this example, the fully qualified element name is nonsinusoidal.saw because the signal named saw is in the nested bus named nonsinusoidal.

While this example shows how to select elements from the input bus from the block diagram, you can also double-click the Bus Selector block and select output elements in the dialog box that opens.

Extended Examples

Ports

Input

expand all

The input virtual or nonvirtual bus contains the elements to be selected.

For arrays of buses, use a Selector block to select the bus that you want to use with the Bus Selector block.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | string | Boolean | fixed point | enumerated | bus
Complex Number Support: Yes

Output

expand all

By default, the block outputs each of the selected elements from a separate output port that is labeled with the corresponding bus element name.

When the Output as virtual bus parameter is selected, the block outputs the selected elements from one port, grouped in a virtual bus.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | string | Boolean | fixed point | enumerated | bus
Complex Number Support: Yes

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

By default, the Property Inspector uses a vertical layout, with the output elements under the list of elements in the bus. To view the elements in the bus and the output elements side by side, click Change layout.

This parameter is read-only.

The list of elements in the bus provides the elements that enter the block, including nested buses and their elements. An arrow next to an element indicates that an input element is a bus. To display the contents of that bus, click the arrow.

To filter the elements in the bus by name with or without regular expression, enter the search term in the Filter box. Do not enclose the search term in quotation marks. Optionally, display the filtered results as a flat list by clicking Show filtered results as a flat list. The flat list uses dot notation to reflect the bus hierarchy. By default, the filtered results appear in a hierarchical tree.

To select the source of an element that enters the block, select the element in the list. Then, click Select source blocks. Alternatively, right-click the element. Then, select Select source blocks. The Property Inspector shows the parameters of the selected source block. When you select the source block of multiple elements, the Property Inspector shows the parameters of the source block with primary selection.

To refresh the list of elements that enter the block, click Refresh. For example, click this button when you change an element name while the dialog box is open.

Tips

  • A green check mark icon appears next to selected output elements.

  • When you pause on a selected output element, a parenthetical displays how many times the Bus Selector block selects that element.

  • Regular expressions let you filter based on whether the input elements match a pattern. For example, enter t$ in the Filter box to display all elements whose names end with a lowercase t. For more informations, see Regular Expressions.

Programmatic Use

To get the block parameter value programmatically, use the get_param function.

Parameter: InputSignals
Values: cell array of element names

Example: get_param(gcb,'InputSignals')

The list of selected elements provides the elements that exit the block. The list uses the fully qualified name for each element.

In the Simulink Editor, when Output as virtual bus is cleared, select elements from the input bus by adding ports to the block.

  1. Click the output edge of the Bus Selector block. Alternatively, when the block receives a bus and all output ports connect to other ports, draw a new line close to the output edge of the Bus Selector block.

  2. Specify an element to select.

In the Property Inspector or Block Parameters dialog box, select elements from the input bus by adding elements to the Output elements list.

  1. In the Elements in the bus list, select one or more elements that you want to add to the block output.

    When you select multiple elements from the Elements in the bus list, the order in which you select them sets their order when you add them to the Output elements list.

  2. Optionally, in the Output elements list, select the element that you want to add elements below. When you select no element, the software adds the elements at the end of the list.

  3. Click Add to output (vertical layout) or Add to output (horizontal layout), depending on the layout of the dialog box. Alternatively, right-click one of the selected elements. Then, click Add to output.

To change the order of the output elements, drag elements in the Output elements list to a different position. Port connectivity is maintained when you change the element order.

To remove elements from the block output, select the elements to remove from the Output elements list. Then, click Remove. Alternatively, right-click one of the selected elements. Then, select Remove.

If an element in the list is not in the input bus, the element name is red. Remove the element from the list of selected elements or modify the input bus to include an element with the specified name. To remove all output elements that are not in the input bus, right-click an element name that is red. Then, select Remove all invalid elements.

Limitations

To avoid a recursion limit, select fewer than 500 elements per Bus Selector block.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: OutputSignals
Values: 'signal1,signal2' (default) | comma-separated list of element names in quotes
Data Types: char | string

Example: set_param(gcb,'OutputSignals','constant,sine')

By default, the block outputs each of the selected elements from a separate output port that is labeled with the corresponding bus element name. To output the selected elements from one port, grouped in a virtual bus, select this parameter.

To convert the output to a nonvirtual bus, insert a Signal Conversion block after the Bus Selector block. Set the Signal Conversion block Output parameter to Nonvirtual bus and set the Data type to a Simulink.Bus object.

When the Output elements list includes only one element and you select this parameter, that element is not wrapped in a bus. For example, if the element is a bus, the output element is that bus. If the element is not a bus, the output element is not a bus.

Dependencies

To use this parameter, the block output must not include messages.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: OutputAsBus
Values: 'off' (default) | 'on'

Example: set_param(gcb,'OutputAsBus','on')

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | half | integer | single | string

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

Tips

By default, the dialog box opens in a vertical layout, with the selected elements under the list of elements in the bus. To view the elements in the bus and the selected output elements side by side, click Change layout.

Extended Capabilities

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Version History

Introduced before R2006a

expand all