How can I programmatically replace a referenced model with a Subsystem in Simulink?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 18 de Jun. de 2018
Editada: MathWorks Support Team
el 2 de Sept. de 2025
I have a Simulink model with a Model Reference.
How can I programmatically replace the "Model" block that references a different model with a "Subsystem" block?
Respuesta aceptada
MathWorks Support Team
el 13 de Jun. de 2025
Editada: MathWorks Support Team
el 2 de Sept. de 2025
To programmatically replace a Model block with a Subsystem block, use the example MATLAB code below.
In this example, the "parent" model references a "child" model using a Model block named "Model." The example MATLAB code adds a Subsystem block "mySub" to the "parent" model and populates "mySub" with the contents of the "child" model.
open_system('parent');
add_block('built-in/Subsystem',['parent/mySub']);
load_system('child');
Simulink.BlockDiagram.copyContentsToSubsystem('child',['parent/mySub']);
pos = get_param('parent/Model','position');
delete_block('parent/Model');
set_param('parent/mySub','position',pos);
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Programmatic Model Editing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!