Copy matlab Simulink SUBSYSTEMS and SFUNCTIONS to another model

3 次查看(过去 30 天)
Hi,
I have to seperate a top level model A and create another model with name B,C and D which contains Masked subsystems, unmasked subsystems and Sfunction models respectively.
While doing so, I am able to get which all are sfunction models and subsystems using "find_system".
But I am not able to copy these found models into a single model B, C or D respectively.
I have tried using "Simulink.BlockDiagram.copyContentsToSubSystem" command but am not able to get the solution.
Please let me know how can I copy all models which are found using "find_subsystem" from A to B , C or D model.
======================================================================
Please find the below code that I have written only for model B for copying subsystem models to model B i.e.,"new_model/System_Model"
%Load the model and find the subsystems and sfunctions
open_system('input')
NoOfMaskedSubsystem = find_system(gcs,'SearchDepth',6, 'LookUnderMasks','all', 'BlockType', 'SubSystem')
NoOfSfunctoin = find_system(gcs,'SearchDepth',6, 'LookUnderMasks','all', 'BlockType', 'S-Function')
NoOfNonMaskedSubsystem = find_system(gcs,'SearchDepth',6, 'LookUnderMasks','none', 'BlockType', 'SubSystem')
% %Create the new model having subsystems model for sfunction and subsystems
sys = 'new_model';
new_system(sys) % Create the model
x = 30;
y = 30;
w = 30;
h = 30;
offset = 60;
pos = [x y+h/4 x+w y+h*.75];
add_block('built-in/Subsystem',[sys '/System_Model'],'Position',pos)
open_system('new_model/System_Model');
%Add Top Level Model
Simulink.BlockDiagram.copyContentsToSubSystem('input', 'new_model/System_Model');

采纳的回答

Ryan G
Ryan G 2012-7-12
You can copy the blocks you find directly without the copy contents function.
For example:
add_block(NoOfNonMaskedSubsystem{1},[gcs '/System_Model'],'Position',pos)
As for you copyContents call, the first input should be model A. I don't know what the 'input' is supposed to be in this case.
  1 个评论
Harsha
Harsha 2012-7-13
Hi. Fix works to copy only one subsystem to the new model. Is there any way that I can copy multiple subsystems to a single model at a time? Thanks in advance.

请先登录,再进行评论。

更多回答(0 个)

类别

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