Main Content

Use Array or Nested Array of Buses with S-Function Builder to Create an S-Function

This example shows how to use S-Function builder 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 S-Function builder as inputs and outputs to build an S-Function.

If you want to use S-Function builder 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

Open This Model

This example shows how to build an S-Function with an array of buses by using 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 S-Function builder where the S-Function is built.

In the C code in 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 S-Function builder, the signal is split through two channel selectors. The Scope blocks display the signals.

Use S-Function Builder with Nested Array of Buses

Open This Model

This example shows how to build an S-Function with a nested array of buses by 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 S-Function builder to build an S-Function.

In the C code in 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 S-Function builder, 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

| | |