Use Array or Nested Array of Buses with S-Function Builder to Create an S-Function
This example shows how to use the S-Function Builder block with arrays of buses and nested arrays of buses. An array of buses is an array whose elements are nonvirtual buses. You can specify arrays of buses as elements in a bus. Arrays of buses, regardless of whether they are nested in a bus, can be used with the S-Function Builder block as inputs and outputs to build an S-Function.
If you want to use the S-Function Builder block with a nonvirtual bus, see Use a Bus with S-Function Builder to Create an S-Function. For more on arrays of buses, see Work with Arrays of Buses.
Use S-Function Builder with Array of Buses
This example shows how to build an S-Function with an array of buses using the S-Function Builder. This model contains two groups of signals, each signal containing a pulse generator and a lower and upper limit scalar. Each of these signals is combined into a bus, and those two buses are combined into an array of buses. The array of buses is then passed through an S-Function Builder block where the S-Function is built.
In the C code in the S-Function Builder, u0[0]
denotes the first element and u0[1]
denotes the second element in the input bus array u0
. Similarly, y0[0]
denotes the first element and y0[1]
denotes the second element of the output bus array y0
.
After going through the S-Function Builder block, the signal is split through two channel selectors. The Scope blocks display the signals.
Use S-Function Builder with Nested Array of Buses
This example shows how to build an S-Function with a nested array of buses using S-Function Builder. This model contains four separate signals that are each turned into a bus, and then the two buses are combined into an array of buses. Those buses are then combined into a bus that contains an array of buses using a Bus Creator block and then passed into an S-Function Builder block to build an S-Function.
In the C code in the S-Function Builder, the output y0
is the nested array of buses. The output y1
is the sum of the elements of the first array of buses, aBusArray
. The elements of aBusArray
are aBusArray[0].aElement
and aBusArray[1].aElement
. The output y2
is the product of the elements of the second array of buses, bBusArray
. The elements of bBusArray
are bBusArray[0].bElement
and bBusArray[1].bElement
.
After passing through the S-Function Builder block, the signal y0
is split back into the original signals as shown. The signal y1
, which is the sum of the first two buses from aBusArray
, is displayed as is y2
, the product of the second two buses from bBusArray
.
See Also
Build S-Functions Automatically Using S-Function Builder | Use a Bus with S-Function Builder to Create an S-Function | Work with Arrays of Buses | Group Nonvirtual Buses in Arrays of Buses