Dealing with array of buses in Simulink®
Updated 1 Sep 2016
Here is the situation. Suppose you have a model that can analyze the properties of a meteor to track its trajectory. You want to use it in a larger model which tracks many such meteors at the same time. You now need a block that can accept a superbus called Mainbus (that contains a lot of subbuses called meteorbus) and split out the relevant subbus (metoerbus).
This block should be able to handles any changes in MainBus and meteorbus automatically on model update (no manual intervention).
Solution: Look at the example “ArrayofBus_example.mdl”. I created a masked subsystem “Meteor Selector” which automatically looks at the Bus Objects (MainBus and meteorbus), figures out how many meteors are in the “MainBus” and the structure of the “misbus” and pulls out the correct meteor.
I simply used a Bus Selector which splits out ALL the meteors and then use a Multiport Switch to pass through the correct meteor(based on input frm the mask) to the outport. The tricky part is to get this to work if the number of meteors in MainBus changes. I got this to happen by writing a script that figures out what needs to be done (at the time of model update) and put that in Mask Initialization callback. Essentially you have to set the correct number of ports for the Bus Selector and the Multiport Switch, delete the existing signal lines and add the required lines.
Open the model “ArrayofBus_example.mdl” and follow the instructions in the annotation.
Vijay Swaminathan (2023). Dealing with array of buses in Simulink® (https://www.mathworks.com/matlabcentral/fileexchange/24745-dealing-with-array-of-buses-in-simulink), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.