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

10 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 31 Jul. 2023
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

Weitere Antworten (0)

Kategorien

Mehr zu Subsystems finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by