- Place a Bus Selector block before the subsystem to identify the signals that could be present in the bus. https://www.mathworks.com/help/simulink/slref/busselector.html.
- Create a custom MATLAB Function block that will check for the missing signals and assign default values to those signals. The output of the Bus Selector block would be the input to this custom block. https://www.mathworks.com/help/simulink/slref/matlabfunction.html.
- Now, after initialising with the default values, leverage a Bus Creator block to reconstruct the bus signals with the new updated values. https://www.mathworks.com/help/simulink/slref/buscreator.html.
how to have an optional bus signal inside a subsystem?
1 view (last 30 days)
Show older comments
Hello,
I want to create a subsystem that I can reuse in different scenarios (maybe as subsystem reference, not really important).
I would like to pass the signal to this subsystem as a virtual bus.
Inside the subsystem I use the in bus element to get the signals I need from the bus.
Now, since I use this subsystem in different models/configurations there are signals that sometimes are present and sometimes are not present inside the virtual bus, like in the example image below: signal3 is not present inside the bus and so simulink throws the error:
Selected signal 'signal3' in the Bus Element Inport block 'untitledeee/Subsystem1/In Bus Element1' cannot be found in the input bus signal.
I would like to use a default value when I recognize that the input is missing. In matlab functions you can easily do this with optional arguments (link: arguments - defaultValue).
My question is: there is a way to replicate the optional arguments of matlab functions inside a subsystem/reference subsystem/model reference?
There is some suggested workaround?
0 Comments
Answers (1)
Ashutosh Thakur
on 17 Jun 2024
Hi Michele,
Simulink does not have a feature for handling optional arguments for the virtual bus in the way MATLAB code can. However, a strategy can be implemented to support this functionality. The following approach can be followed:
The combination of the above-mentioned blocks could help you in reusing your subsystem with optional signal values.
See Also
Categories
Find more on Subsystems 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!