How can I programmatically replace a referenced model with a Subsystem in Simulink?
조회 수: 11 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2018년 6월 18일
답변: MathWorks Support Team
2018년 6월 18일
I have a Simulink model with a model reference. I would like to programmatically replace the 'Model' block with a 'Subsystem' block.
채택된 답변
MathWorks Support Team
2018년 6월 18일
Assuming that you have a 'parent.slx' model which references a model 'child.slx' (whose block name is 'Model' in the parent Simulink model), use either of the following options:
1)
>> 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);
2)
>> open_system('parent');
>> load_system('child');
>> convert2subsys('child');
>> add_block('child/Subsystem','parent/mySub');
>> pos = get_param('parent/Model','position');
>> delete_block('parent/Model');
>> set_param('parent/mySub','position',pos);
>> close_system('child',0);
where 'convert2subsys' is defined at the following link:
Please refer to the attachment for further details.
댓글 수: 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!