Names of connected outputs to inports of selected subsystem

6 ビュー (過去 30 日間)
Ewela
Ewela 2021 年 10 月 12 日
編集済み: Ewela 2021 年 10 月 20 日
I want to get the proper name of the connected port but the get_param gives me the incorrect names:
block_of_interest_params = get_param(block_of_interest,'PortConnectivity');
connected_inports_handle = find_system(block_of_interest_params(i).SrcBlock,'SearchDepth',1,'LookUnderMasks','all','BlockType','Outport','Port',block_of_interest_params(i).Type)
connected_block_nameport{i} = get_param(connected_inports_handle,'Name') %connected block portname
I need to have port names of the outport that are connected to In5 and In6.
and my incorrect result:
correct is when tags out2 are out1.
Thank you in advance for help!
  10 件のコメント
Ewela
Ewela 2021 年 10 月 12 日
I need the name: Out1 and Out3 not: Subsystem:2. It is possible?
Ewela
Ewela 2021 年 10 月 12 日
The line:
get(get(a.Inport,'line'),'SourcePort')
get the error:
Error using get
Conversion to double from cell is not possible

サインインしてコメントする。

採用された回答

C B
C B 2021 年 10 月 12 日
編集済み: C B 2021 年 10 月 12 日
@Ewelina Cholodowicz I hope this will solve your issue :)
Please let me know if you stuck at any point, or any point is not clear.
load_system('sampleModel')
block_of_interest = 'sampleModel/Subsystem1';
block_of_interest_PH = get_param(block_of_interest,'PortHandles');% get all ports
for i= 1: length(block_of_interest_PH.Inport)% loop through all inports
lineHnd = get(block_of_interest_PH.Inport(i),'line');%get line handle to trace back
if lineHnd~= -1 % if line handle is present
SubName = get(lineHnd,'SourcePort');% get source port number of sub
SubHnd = get(lineHnd,'SrcBlockHandle');% get source block i.e Subsystem
OPName = get(find_system(SubHnd,'BlockType','Outport'),'Name');% get all outport name of subsystem
GotoBlockName = OPName{str2num(extractAfter(SubName,':'))}% get specific outport name
%add goto block logic below GotoBlockName have correct name
end
end
GotoBlockName = 'Out1'
GotoBlockName = 'Out3'
The above code shows how to get outport name please add from and gotot logic below that
  5 件のコメント
C B
C B 2021 年 10 月 20 日
編集済み: C B 2021 年 10 月 20 日
Does line connected to multiple subsystem?
Ewela
Ewela 2021 年 10 月 20 日
編集済み: Ewela 2021 年 10 月 20 日
yes, line is connected to two subsystems.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by