Find names of ports in Subsystem connected to input ports

21 次查看(过去 30 天)
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 个评论
ciming zhu
ciming zhu 2023-4-26
I have the same problem as you,I wonder that did you figure out how to solve this problem?Thanks a lot!!

请先登录,再进行评论。

回答(2 个)

Israa Abdullah
Israa Abdullah 2019-11-17
What is the answer please?

Oleksandr Pylypenko
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

类别

Help CenterFile Exchange 中查找有关 Interactive Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by