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!