Find names of ports in Subsystem connected to input ports
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149820/image.png)
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 Kommentar
ciming zhu
am 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!!
Antworten (2)
Oleksandr Pylypenko
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Subsystems finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!