I have this code that is supposed to change the referenced subsystems in a model to normal subsystems, because I have another script that no longer works on matlab 2020, only on 2017, due to the change of the applications libraries to referenced subsystems. When I run it, I get multiple:
*** W02293: SIMULINK DATA TYPE RESTRICTIONS:
*** Could not perform min/max logging or overflow detection for signal.
*** The ufix1 Simulink data type is not supported.
Followed by:
Error using change (line 4)
Invalid Simulink object handle
Anybody know why? I use the version Matlab R2020b with TargetLink 5.1p1
refSubsystem = 'subsys20b';
modelName = 'modelRefSubsys20b';
open_system("Application Name");
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);
I just had a similar error wanting to revert Referenced Subsystems to simple Subsystems. In my case however, I did not want to do that programmatically.
I use MATLAB2021a and had a project initializing the Search Paths.
Removing the Referenced Subsystem link from the Block Parameters raised:
and prevented me to save the model. The workaround that I found was:
I am aware that you wanted to perform this programmatically and I hope this helps you or someone else. Keep in mind, I am no expert. I simply messed around and found something that worked for me.