How do I programmatically change the subsystem reference in a Simulink model on MacOS using MATLAB R2022b?

10 ビュー (過去 30 日間)
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
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 件)

カテゴリ

Help Center および File ExchangeSubsystems についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by