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

10 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 31 Lug 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

Più risposte (0)

Categorie

Scopri di più su Subsystems in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by