Clear Filters
Clear Filters

How to iterate through a bus object intil I have a struct of primitives which match RTW output with a script

32 views (last 30 days)
We have a model which we generate code with. There are inputs and outputs, and +these are typically buses. When we generate code, these are represented as structs of primitives (and other object, not sure if they are enums or more buses yet).
I have a matlab script which gets the interface properties of the model, so now I need to drill down into the buses.
Any help would be greatly appreciated. I have also been searching for assistance online, and ran across this - http://www.mathworks.com/help/toolbox/simulink/sfg/ssgetnumoutputports.html, but no idea what a SimStruct is, or how I would get one. Or, perhaps I am heading down the wrong path entirely...
Thanks, -Kevin

Answers (2)

Fangjun Jiang
Fangjun Jiang on 3 Jun 2011
You mention "a bus object" in the title. Do you have a Simulink.Bus object in the base workspace? If you do, then it is relatively easy to iterate its structure to get the elements. You mention your inputs are bus, then the bus must be defined somewhere else, maybe other model that your model is interfacing with. Then you need to go to the source to find the information. You also have outputs as bus. I assume it is created by the Bus Creator block. Select the Bus Creator block, run get(gcbh,'InputSignalNames'). You will see some signal names or blank if the signal lines are not labeled. Some signal lines may come from another Bus Creator block, which will force you to chase it up-chain. Another way to get at least all the signal names in a nested bus is to work it out through a Bus Selector block. You must have a Bus Selector block in the model. The input to the Bus Selector block is your out-most bus. Press Ctrl-D to update your model, select the Bus Selector block, run get(gcbh,'InputSignals'). You will see some cell array or strings. String means signal name. Cell array means another bus. You'll need to write a recursive function to get down to all the signal names. I have the code but I'll leave you to write your own.

Guy Rouleau
Guy Rouleau on 5 Jun 2011
I am not sure what you mean by "drill down into the buses".
Probably the one of the "Simulink.Bus.xxx" functions can be useful to get what you want. I recommend looking at all the syntax for:
and others related.

Categories

Find more on Composite Interfaces in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!