How do I programmatically change the subsystem reference in a Simulink model on MacOS using MATLAB R2022b?
10 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2023-7-31
回答: MathWorks Support Team
2023-8-3
I am running a Simulink model from MATLAB script on MacOs 12.x with MATLAB R2022b.
I'm using a model with subsystems which need to be changed based on my requirements for my project. I have two subsystems called "product_2" and "product_3" that I'd like to switch between without opening Simulink.
Is there a way to change the subsystem in the Simulink model without manually changing from the GUI?
采纳的回答
MathWorks Support Team
2023-7-31
One way to change the subsystem reference in the MATLAB editor is by using the “set_param” function in this way:
set_param(path_subsys_ref,'ReferencedSubsystem',subsys_var);
where "path_subsys_ref" is the path to Subsystem Reference / name of the Simulink model, and "subsys_var" is the desired Subsystem file name. In this case, the "path_subsys_ref" would be "test_model" and "subsys_var" would be both "product_2" and "product_3".
As an example, here is some code that would help with programmatically changing the Subsystem Reference:
simIn = Simulink.SimulationInput("test_model");
load_system("test_model")
set_param('test_model/Subsystem Reference','ReferencedSubsystem','product_2'); %Select model name, then the block reference
out = sim(simIn);
out.simout.Data
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!