Filter löschen
Filter löschen

Copy matlab Simulink SUBSYSTEMS and SFUNCTIONS to another model

3 Ansichten (letzte 30 Tage)
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');

Akzeptierte Antwort

Ryan G
Ryan G am 12 Jul. 2012
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 Kommentar
Harsha
Harsha am 13 Jul. 2012
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Subsystems finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by