Copying a subsystem from one model to another

조회 수: 74 (최근 30일)
Michael Joslin
Michael Joslin 2011년 9월 6일
댓글: Vishal Varadraj 2022년 6월 24일
I need to copy a subsystem and all of the blocks attached to the input and output ports of it to a new model for modification. This needs to be done all in script because I am trying to automate a RCP process. The subsystem in question is in a layer with several other subsystems in it, and all of these belong to a higher parent system. Any ideas on how i can target the desired section of block diagram and copy it to a new model?

채택된 답변

Guy Rouleau
Guy Rouleau 2011년 9월 6일
Fangjun's solution is possible, but this is probably simpler with function like:
Simulink.SubSystem.copyContentsToBlockDiagram
and
Simulink.BlockDiagram.copyContentsToSubSystem
  댓글 수: 5
Fangjun Jiang
Fangjun Jiang 2011년 9월 8일
Guy, this is not my use case. This is the OP's question. The OP wants to copy not only the subsystem block, but also copy "all of the blocks attached to the input and output ports of it to a new model". I certainly can see the need for such a use case.
What you suggested is not that much different than using add_block(). The key to solve this problem is to find all the connected blocks outside of the subsystem block and copy them. I am not convinced that the problem is solvable using just the two methods mentioned in your answer.
Guy Rouleau
Guy Rouleau 2011년 9월 9일
Now I see... I agree that this will require some find_system and copy_block, add_line, etc, to find all the connected blocks outside of the subsystem block and copy them.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 9월 6일
It can be done although it takes some coding.
  1. Use add_block(SubSysBlockInOriginalModel,Destination) to copy the Subsystem block
  2. Use C=get_param(SubSysBlockInOriginalModel,'PortConnectivity')
  3. C is a structure array, check the meaning of its field from Simulink document or http://www.mathworks.com/help/toolbox/simulink/slref/f23-7517.html.
  4. Go through a loop. For Inports, find the SrcBlock handle, use add_block() to add the block, use add_line() to add the signal connection. For Outports, find the DstBlock handle or handles because the outport may connect to more than one blocks. Go through another loop to add each destination block and signal line.
  5. Try it and it should work out. add_block works on block handle too. You can use the same block name in the new model. add_line() may need a little work if you never used it before. Ask again or comment further if you need help.
  댓글 수: 7
Euan Russano
Euan Russano 2015년 1월 5일
How? I am having the same problem...
Vishal Varadraj
Vishal Varadraj 2022년 6월 24일
Could you please help me out in structuring the for loop. I am having trouble understanding the parameters. Thanks!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by