I have signals in a SIMULINK bus and I would like to select specific signals from it. The issue is that I want to run an initialization script that will decide which subset of signals to select. I see that you can select bus signals manually via the bus selector block. Is there any way to perform this function programmatically?
John Michell answered .
2025-12-15
The key parameter for a Bus Selector block is OutputSignals, which specifies the selected elements as a comma-separated string of element names (hierarchical names for nested buses, e.g., 'bus1.signalA,bus2.nestedSignal').
Assume your model is loaded, and the Bus Selector block path is 'myModel/mySubsystem/BusSelector1'.
Get current selected signals (optional, to build upon existing):
currentSignals = get_param('myModel/mySubsystem/BusSelector1', 'OutputSignals');
disp(currentSignals); % e.g., 'signal1,signal2,nested.busSignal'
Set new selected signals (overwrites all; specify the full list):
set_param('myModel/mySubsystem/BusSelector1', 'OutputSignals', 'signalA,signalB,nestedBus.signalX');
To add to existing without overwriting:
current = get_param('myModel/mySubsystem/BusSelector1', 'OutputSignals');
newList = [current ',newSignal']; % Append (add comma if current not empty)
if ~isempty(current)
newList = [current ',newSignal'];
else
newList = 'newSignal';
end
set_param('myModel/mySubsystem/BusSelector1', 'OutputSignals', newList);
set_param('myModel/mySubsystem/BusSelector1', 'OutputAsBus', 'on'); % or 'off' for separate ports
set_param('myModel', 'SimulationCommand', 'update');