Copying a subsystem from one model to another

60 次查看(过去 30 天)
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 个评论
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