how to have an optional bus signal inside a subsystem?

5 次查看(过去 30 天)
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?

回答(1 个)

Ashutosh Thakur
Ashutosh Thakur 2024-6-17
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.
  1 个评论
Michele Oro
Michele Oro 2024-6-17
Hi Ashutosh,
thank you for your suggestion. Unfortunately this solution at the core is manual solution while I am looking for something that could handle the situation with some automation.
But you are also right saying that simulink does not have this feature so I will probably have to accept some level of manual action.
Mic

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by