Copying a subsystem from one model to another
71 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Michael Joslin
le 6 Sep 2011
Commenté : Vishal Varadraj
le 24 Juin 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 commentaires
Réponse acceptée
Guy Rouleau
le 6 Sep 2011
Fangjun's solution is possible, but this is probably simpler with function like:
Simulink.SubSystem.copyContentsToBlockDiagram
and
Simulink.BlockDiagram.copyContentsToSubSystem
5 commentaires
Fangjun Jiang
le 8 Sep 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
le 9 Sep 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.
Plus de réponses (1)
Fangjun Jiang
le 6 Sep 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 commentaires
Vishal Varadraj
le 24 Juin 2022
Could you please help me out in structuring the for loop. I am having trouble understanding the parameters. Thanks!!
Voir également
Catégories
En savoir plus sur Subsystems dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!