Find names of ports in Subsystem connected to input ports
20 views (last 30 days)
Show older comments
I have some input ports connected to the port of a subsystem. I know the names of all input ports. How to find the names of ports in subsystem which are connected to inports. For example: If I consider inport A1, I should findout the name B1, which is the name of the port in system connected to A1.
Thanks.
1 Comment
ciming zhu
on 26 Apr 2023
I have the same problem as you,I wonder that did you figure out how to solve this problem?Thanks a lot!!
Answers (2)
Oleksandr Pylypenko
on 4 Feb 2020
this script will sustitute name of subsystem inport with respect to connected outer inport. It will work also with only some ONE block in the middle between outer inport and subsystem.
% select subsystem
sel_subsystems = find_system(gcs,'Selected','on');
if(length(sel_subsystems)==2)
sel_subsystem = sel_subsystems(2);
else
sel_subsystem = sel_subsystems;
end
block_of_interest = get_param(cell2mat(sel_subsystem),'Handle');
% subsystem inport handle
sub_handles = find_system(block_of_interest, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Inport');
selected_pc = get_param(block_of_interest,'PortConnectivity');
SrcBlock_h = [selected_pc(:).SrcBlock];
%check if connected block is port type block: BlockType == Inport
for blk=1:length(SrcBlock_h)
connected_blocktype = get_param(SrcBlock_h(blk),'BlockType');
if (contains(connected_blocktype,'Inport'))
% Substitute name
inport_name = get_param(SrcBlock_h(blk),'Name');
set_param(sub_handles(blk),'Name',inport_name);
else
% check block connected to this one
pc_L2 = get_param(SrcBlock_h(blk),'PortConnectivity');
SrcBlock_L2_h = [pc_L2(:).SrcBlock];
if(length(SrcBlock_L2_h)>1)
disp("Connection Level 2 error. More than 1 connection!")
return;
end
inport_name = get_param(SrcBlock_L2_h(1),'Name');
set_param(sub_handles(blk),'Name',inport_name);
end
end
0 Comments
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!