MATLAB: How to retrieve names of signals in a bus when the signal names have been propagated by Simulink

simulink

I would like to show the signal structure created in a bus selector or bus creator block with a command similar to GET_PARAM.
As long as the signal names have not been propagated, these names can be obtained by using GET_PARAM with the 'InputSignalNames' property on the Bus Creator block. When the signal names have been propagated, the output is as follows, using the busdemo demonstration model included with Simulink:
busdemo;
get_param('busdemo/Bus Creator','inputSignalNames')
The output is the following:
'<bus1>' 'bus2<Clock, Pulse, Sine>'
I would like to automatically show the content of bus1.

Best Answer

This enhancement has been incorporated in Release 2010a (R2010a). For previous product releases, read below for any possible workarounds:
The ability to use a command-line command to retrieve the names of propagated signals in a bus signal is not available in Simulink.
To work around this issue, use the following code:
busdemo
ph = get_param('busdemo/Bus Creator', 'porthandles')
set_param(ph.Outport, 'CacheCompiledBusStruct', 'on')
busdemo([],[],[],'compile')
bs = get_param(ph.Outport, 'CompiledBusStruct')
busdemo([],[],[],'term')
The variable 'bs' will contain information on the bus signal coming out of the Bus Creator. You can recursively walk through this structure to determine all actual sources of the bus and hence all source data types, dimensions, signal names, etc.
Note that the following code makes use of the internal compiled property 'CacheCompiledBusStruct' and hence is subject to change in future releases.
Another workaround to retrieve the names of signals in a bus is to pass all the Bus Creator outputs to a Bus Selector block, which selects all of the signals from the Bus Creator block, then use the following code to extract the signal names, where the Bus Selector block is the currently selected block:
get_param(gcb, 'OutputSignals')