refSubsystem = 'subsys20b'; modelName = 'modelRefSubsys20b'; open_system(modelName); oldBlock = [ modelName '/Subsystem Reference']; newBlock = [ modelName '/subsystem']; % create a copy of the referenced subsystem add_block('built-in/Subsystem', newBlock) Simulink.BlockDiagram.copyContentsToSubsystem(refSubsystem, newBlock) % Retrieve useful info from the old block t1 = get_param(oldBlock, 'Portconnectivity'); t2 = get_param(oldBlock, 'PortHandles'); t3 = get_param(newBlock, 'PortHandles'); % delete old lines h = get_param(oldBlock, 'LineHandles'); ni = numel(h.Inport); no = numel(h.Outport); delete_line(h.Inport); delete_line(h.Outport); % create connections to new block for i=1:numel(t2.Inport) srcBkhdl = t1(i).SrcBlock; % source block handle srcNm = getfullname(srcBkhdl); % source block name srcBkPts = get_param(srcNm, 'PortHandles'); % source block port handles srcPt = srcBkPts.Outport(t1(i).SrcPort+1); % source port dstPt = t3.Inport(i); % destination port add_line(modelName, srcPt, dstPt); end % create connections from new block for i=1:numel(t2.Outport) dstBkhdl = t1(ni+i).DstBlock; % dest block handle dstNm = getfullname(dstBkhdl); % dest block name dstBkPts = get_param(dstNm, 'PortHandles'); % dest block port handles dstPt = dstBkPts.Inport(t1(ni+i).DstPort+1); % dest port srcPt = t3.Outport(i); % src port add_line(modelName, srcPt, dstPt); end % copy to same position pos = get_param(oldBlock, 'position'); set_param(newBlock, 'position', pos); % remove old block delete_block(oldBlock); % save changes save_system(modelName); % replace_block might work.. Haven't tried % replace_block(modelName, 'Subsystem Reference', 'subsystem')
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.