Question
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?
Related Questions
Expert Answer
John Michell
PhD Expert
Answered Aug 21, 2026
Use set_param on the 'OutputSignals' Parameter
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').
Example Code
Assume your model is loaded, and the Bus Selector block path is 'myModel/mySubsystem/BusSelector1'.
-
Get current selected signals (optional, to build upon existing):
matlabcurrentSignals = get_param('myModel/mySubsystem/BusSelector1', 'OutputSignals'); disp(currentSignals); % e.g., 'signal1,signal2,nested.busSignal' -
Set new selected signals (overwrites all; specify the full list):
matlabset_param('myModel/mySubsystem/BusSelector1', 'OutputSignals', 'signalA,signalB,nestedBus.signalX');- This updates the block: adds/removes output ports accordingly.
- Element names must match exactly what's available in the input bus (case-sensitive, including hierarchy like 'topBus.subBus.element').
- For a single element: 'mySignal'
- For none (clear all): '' (empty string)
-
To add to existing without overwriting:
matlabcurrent = 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);
Additional Options
- Output as virtual bus: If you want selected elements grouped into one virtual bus output port:
matlab
set_param('myModel/mySubsystem/BusSelector1', 'OutputAsBus', 'on'); % or 'off' for separate ports - After setting, update the model diagram if needed:
matlab
set_param('myModel', 'SimulationCommand', 'update');
Have a different question? Ask here