Copying a subsystem from one model to another
65 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Michael Joslin
il 6 Set 2011
Commentato: Vishal Varadraj
il 24 Giu 2022
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?
0 Commenti
Risposta accettata
Guy Rouleau
il 6 Set 2011
Fangjun's solution is possible, but this is probably simpler with function like:
Simulink.SubSystem.copyContentsToBlockDiagram
and
Simulink.BlockDiagram.copyContentsToSubSystem
5 Commenti
Fangjun Jiang
il 8 Set 2011
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
il 9 Set 2011
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.
Più risposte (1)
Fangjun Jiang
il 6 Set 2011
It can be done although it takes some coding.
- Use add_block(SubSysBlockInOriginalModel,Destination) to copy the Subsystem block
- Use C=get_param(SubSysBlockInOriginalModel,'PortConnectivity')
- 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.
- 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.
- 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 Commenti
Vishal Varadraj
il 24 Giu 2022
Could you please help me out in structuring the for loop. I am having trouble understanding the parameters. Thanks!!
Vedere anche
Categorie
Scopri di più su Subsystems in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!