Main Content

Work with Arrays of Buses

Setting up a model to use an array of buses usually involves these tasks:

  1. Define the array of buses. SeeCreate Array of Buses from Nonvirtual Buses.

  2. Add a subsystem for performing iterative processing on each element of the array of buses. See执行迭代Processing.

  3. Model your scalar algorithm within the iterative processing subsystem.

    1. Operate on the array of buses (usingSelectorandAssignment块)。

    2. Use theBus SelectorandBus Assignmentblocks to select elements from, or assign elements to, a nonvirtual bus within the subsystem.

    SeeAssign Values into Arrays of BusesandSelect Bus Elements from Array of Buses.

  4. Optionally, import or log array of buses data. SeeImport Array of Buses DataandLog Arrays of Buses.

The resulting model creates the array of buses and uses a subsystem to iteratively process the elements of the array.

Nonvirtual buses are grouped in an array of buses that is input to a subsystem that provides iterative processing.

执行迭代Processing

您可以执行迭代处理在公共汽车上哒ta of an array of buses using blocks such as theFor Each Subsystem,While Iterator Subsystem, andFor Iterator Subsystemblocks. You can use one of these blocks to perform the same kind of processing on:

  • Each bus in the array of buses

  • A selected subset of buses in the array of buses

Assign Values into Arrays of Buses

How you assign values to one or more elements in an array of buses depends on your modeling requirement.

Select Bus Elements from Array of Buses

To select a bus element from an array of buses:

  1. Use aSelectorblock to select a bus from the array of buses. The input array of buses can have any dimension. The output bus of theSelectorblock is a selected or reordered set of elements from the input array of buses.

  2. Use aBus Selectorblock to select a bus element from the bus. The input for theBus Selectorblock must be a bus.

For an example, seeModel Arrays of Buses.

Import Array of Buses Data

Use a rootInportblock to import (load) an array of structures of MATLAB®timeseriesobjects for an array of buses. You can import partial data into the array of buses. For more information, seeImport Array of Buses Data.

You cannot use aFrom WorkspaceorFrom Fileblock to import data for an array of buses.

Log Arrays of Buses

To export an array of buses, mark the signal for signal logging. For more information, seeSave Run-Time Data from Simulation.

Note

金宝app®does not log signals inside referenced models in rapid accelerator mode.

To access the signal logging data for a specific signal in an array of buses, navigate through the structure hierarchy and specify the index to the specific signal. For details, seeAccess Array of Buses Signal Logging Data.

Root level bus outputs are not logged when you select theOutputconfiguration parameter. Use standard signal logging instead, as described inExport Signal Data Using Signal Logging.

Do not use signal logging for buses or arrays of buses directly from within a for-each subsystem. Either use aBus Selectorblock to select the bus element signals to log or add anOutportblock outside of the subsystem and then log that signal. For details, seeLog Signals in For Each Subsystems.

Note

Signal logging is not supported for arrays of buses with variable-size signals.

Initialize Arrays of Buses

To specify a unique initial value for each of the individual signals in an array of buses, you can use an array of initial condition structures. Each structure in the array initializes one of the buses.

To initialize an array of buses with structure parameters, you can use:

  • The number0. In this case, all the individual signals in the array of buses use the initial value0.

  • A scalarstructthat represents the same hierarchy of fields and field names as the bus type. In this case, the scalar structure expands to initialize each of the individual signals in the array of buses.

  • An array of structures that specifies an initial value for each of the individual signals in the array of buses.

    If you use an array of structures, all the structures in the array must have the same hierarchy of fields. Each field in the hierarchy must have the same characteristics across the array:

    • Field name

    • Numeric data type, such assingleorint32

    • Complexity

    • Dimensions

You cannot use partial structures.

For examples, seeInitialize Buses and Arrays of Buses Using Bus EditorandInitialize Arrays of Buses Programmatically.

Code Generation

Code generation for arrays of buses produces structures with a specific format. SeeCode Generation for Arrays of Buses.

Note

Code generation is not supported for arrays of buses with variable-size signals.

Related Topics