文档

Work with Array of Buses Signals

Set Up Model for Arrays of Buses

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

  1. 定义公共汽车数组(请参阅Define an Array of Buses).

  2. 一个dd a subsystem for performing iterative processing on each element of the array of buses. For example, use a对于每个子系统block or an迭代器堵塞。连接从加入block to the iterative processing subsystem. SeePerform Iterative Processing

  3. 在迭代处理子系统中对标量算法进行建模(例如,每个子系统)。

    1. 在一系列公共汽车上操作(使用Selector一个nd任务blocks).

    2. 使用总线选择器一个nd巴士分配从子系统中的标量总线中选择元素或分配元素的块。

    一个ssign Values into an Array of Buses一个nd从一系列巴士中选择公交元素

  4. 可选地,导入或日志总线数据。看导入总线数据一个ndLog Array of Buses Signals

最终的模型包括这些组件。

Perform Iterative Processing

You can perform iterative processing on the bus signal data of an array of buses using blocks such as a对于每个子系统block, aWhile Iterator Subsystem块或一个For Iterator Subsystem堵塞。您可以使用这些块之一来执行相同类型的处理:

  • Each bus in the array of buses

  • 公共汽车数组中选定的公共汽车子集

一个ssign Values into an Array of Buses

To assign a value to a signal within an array of buses, use:

  1. 一个巴士分配块将值分配给总线元素

  2. 一个任务将公共汽车分配到公共​​汽车数组

使用任务块将值分配给总线数组中的指定元素。

例如,在sldemo_bus_arrays模型,任务块将值分配给总线数组的第一个元素。

To assign bus elements within a bus signal, use the巴士分配堵塞。这input for the巴士分配块必须是标量总线信号。

一个ssign into Array of Buses Signals

您可以使用巴士分配块分配或完全替换为总线阵列的子分机。要在一系列总线内分配嵌套总线的数据,或者用总线数组对某些元素进行部分分配,您可以使用MATLABFunction堵塞。

For example, suppose that you have this bus structure:

这bus has a孩子们element, which is a sub-bus array. This example shows how to assign to elementC和元素一个。这Inport一个ndOutport块使用父母bus object. To define the assignments, this example uses aMATLABFunctionblock, because you cannot assign into element一个用一个巴士分配or任务堵塞。

MATLABFunction块使用此功能代码进行分配:

functiony = fcn(u) y = u; y.c = false;为了IDX = 1:长度(Y.Children)Y.Children(IDX).A = INT32(ZEROS(5,1));结尾

从一系列巴士中选择公交元素

要在总线数组中选择一个信号,请使用:

  1. Selector街区以在公共汽车阵列中找到合适的总线。

  2. 总线选择器block to select the signal.

用一个Selector块以选择一系列总线的元素。总线的输入阵列可以具有任何维度。输出总线信号Selector块是从总线的输入阵列中选择或重新排序的元素集。

For example, thesldemo_bus_arraysmodel uses Selector blocks to select elements from the array of buses signal that the任务一个nd对于每个子系统阻止输出。在此示例中,这里是块参数对话框Selectorblock that selects the first element:

To select bus elements within a bus signal, use the总线选择器堵塞。这input for the总线选择器块必须是标量总线信号。

导入总线数据

用一个rootInport导入(负载)MATLAB的结构数组®时间序列objects for an array of buses. You can import partial data into the array of buses.

有关详细信息,请参阅导入总线数据

You cannot use a从工作区or从文件阻止导入一系列总线的数据。

Log Array of Buses Signals

要导出一系列总线信号,请标记信号记录的信号。有关更多信息,请参阅从模拟中保存运行时数据

笔记

万博1manbetx®不会在快速加速器模式下引用模型中的记录信号。

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, see访问一系列巴士信号记录数据

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.

这是一个示例,该示例显示了如何初始化一系列总线。假设您定义公共汽车类型MyData一个nd高压总线

假设您设置信号元素的数据类型温度int16, and the data type of the elementsS1一个ndS2double

To specify initial conditions for an array of buses, you can create a variable whose value is an array of initial condition structures.

initValues(1).temperature = int16(5); initValues(1).pressure.s1 = 9.87; initValues(1).pressure.s2 = 8.71; initValues(2).temperature = int16(20); initValues(2).pressure.s1 = 10.21; initValues(2).pressure.s2 = 9.56; initValues(3).temperature = int16(35); initValues(3).pressure.s1 = 8.98; initValues(3).pressure.s2 = 9.17;

这variableinitValues提供了三个总线阵列的信号的初始条件。您可以使用initValues至specify theInitial conditionparameter of a block such asUnit Delay

另外,您可以使用单个标量结构来指定数组中所有总线的相同初始条件。

initscruct。温度= int16(15); initStruct.pressure.s1 = 10.32; initStruct.pressure.s2 = 9.46;

If you specifyinitscructin theInitial conditionparameter of a block, each bus in the array uses the same initial value,15, for the signal element温度。Similarly, the buses use the initial value10.32为了the element压力.s1和价值9.46为了the elementpressure.s2

要为使用大量信号元素层次结构的总线创建一系列结构,请考虑使用该函数万博1manbetxsimulink.bus.creatematlabstruct

此示例显示了如何初始化嵌套的总线阵列。为复杂的信号层次结构创建一个初始条件结构,该结构包括总线的嵌套阵列。

  1. In the Bus Editor, create the bus objectsMyData一个nd高压总线

  2. 在层次结构窗格中,选择总线元素pressure。设置方面财产为[1 3]

  3. Create an array of four initialization structures by using the function万博1manbetxsimulink.bus.creatematlabstruct。将数组存储在变量中initscruct。Initialize all the individual signals to the ground value,0

    initscruct 万博1manbetx= simulink.bus.creatematlabStruct('MyData',[],[1 4]);

  4. In the base workspace, double-click the variableinitscruct至view it in the variable editor.

    这four structures in the array each have the fields温度一个ndpressure

  5. To inspect apressure,双击其中之一。

    四个的价值pressurefields is an array of three substructures. Each substructure has the fieldsS1一个ndS2

  6. 为了在总线数组中为信号提供唯一的初始化值,您可以使用变量编辑器手动指定值。

    一个lternatively, you can write a script. For example, to access the fieldS1of the second substructurepressure在第三个结构中initscruct使用这段代码:

    Initscruct(3).pressure(2).s1 = 15.35;

代码生成

Code generation for array of buses signals produces structures with a specific format. See代码生成为了一个rrays of Buses

Related Topics

Was this topic helpful?