MATLAB: How to create an array of buses from Constant blocks defining the basic structure of the bus

simulink

I am trying to create an array of 100 buses in Simulink. Since I have 100 elements in the array, each element has the same basic structure. I wanted to use a Constant block to specify the basic structure and somehow multiply it by 100 to create an array of structures. The constant block does not have any way to specify its output size, so I need to copy the Constant block 100 times to do this.
Is there any better way of doing it?

Best Answer

It is possible to use a For Each subsystem block to create a bus array with all elements having a pre-defined structure.
Constant blocks describing the structure's fields are used as input to a Bus Creator block inside a For Each subsystem. Then, you use a Signal Specification block to define the output of the For Each subsystem to have a particular dimension (the desired dimensions of your bus array). You use the output signal (with specified dimensions) as a feedback to the For Each subsystem. The For Each subsytem iterates over the dimensions of this feedback signal, copying the basic structure to create a bus array with the desired dimensions.
Refer to the attached example model (CreateBusArray) showing this process. The model also has notes explaning some of the settings necessary to make this work.
The following doc page discusses this approach in detail: