How can I programmatically replace a referenced model with a Subsystem in Simulink?
16 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2018-6-18
编辑: MathWorks Support Team
2025-9-2
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?
采纳的回答
MathWorks Support Team
2025-6-13
编辑:MathWorks Support Team
2025-9-2
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!