I am trying to "trace" signals through a model, from the outports back to the inports. My script will go into a subsystem in the model, however, when it gets to the inports in that subsystem, I do not know how to find the corresponding signal/source block from the level above. Can anyone provide some help on how to do this? To trace into the subsystem, I am using:
subhandle = find_system(handle, 'LookUnderMasks', 'all', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Outport');
Perhaps there is something similar to use to get back up a level?
I am also having trouble finding a matching GoTo block when I get to a From block, so any help would be appreciated. Thanks

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2018년 5월 22일
편집: Fangjun Jiang 2018년 5월 23일

0 개 추천

To find out the source block that is connected to the Inport block in F14
f14;
InportBlock='f14/Controller/alpha (rad)';
PortNumber=str2double(get_param(InportBlock,'Port'));
Parent=get_param(InportBlock,'Parent');
PortCon=get_param(Parent,'PortConnectivity');
SrcBlock=getfullname(PortCon(PortNumber).SrcBlock)

댓글 수: 8

Christopher Lotysz
Christopher Lotysz 2018년 5월 24일
Thank you for the reply, this seems to work. Do you have any insight to find the matching GoTo block from a From block? Or finding the correct Outport inside of a subsystem?
Thanks
Fangjun Jiang
Fangjun Jiang 2018년 5월 24일
편집: Fangjun Jiang 2018년 5월 24일
To find the matching GoTo block, you will need to get the "GotoTag" of the From block, then use find_system() to find the Goto block with the matching "GotoTag".
To find the connection of an Outport inside of a subsystem is similar to above, get the Outport port number and then PortCon(PortNumber).DstBlock. Note that there might be multiple destinations.
Christopher Lotysz
Christopher Lotysz 2018년 5월 31일
Thank you!
When I use Port Connectivity, I am able to use PortCon(PortNumber).DstBlock to find the destination blocks, however, what I want to know is the "source block" for the Outports of the subsystem. PortCon does not give the handles of the ports themselves which makes it difficult. Any ideas? Thanks!
Fangjun Jiang
Fangjun Jiang 2018년 5월 31일
Get the 'PortConnectivity' of the Outport block itself, then get the .SrcBlock
Christopher Lotysz
Christopher Lotysz 2018년 5월 31일
Right, but how do I find the Outport block itself? That was my original question.
Fangjun Jiang
Fangjun Jiang 2018년 5월 31일
Every block has its "PortConnectivity" value. You can use it to trace the block's connection to the source or destinations. The exception is the Inport and Outport block. You need to get the "PortConnectivity" of its "Parent" (subsystem) block, combine with the port number to get the source for the Inport block and destinations for the Outport block.
If this still won't solve your problem, please use the f14 example model, specify what is known (such as block path, subsystem name, port number, etc) and what is the expected target.
Christopher Lotysz
Christopher Lotysz 2018년 6월 7일
이동: Fangjun Jiang 2024년 5월 16일
Is the F14 model a fictional one, or is there a model I can view somewhere to generate an example? Thanks
Fangjun Jiang
Fangjun Jiang 2018년 6월 7일
이동: Fangjun Jiang 2024년 5월 16일
f14 is an example model in Simulink

댓글을 달려면 로그인하십시오.

omar elkawokgy
omar elkawokgy 2024년 5월 16일

0 개 추천

I suggest you use line instead as so:
%getting root level signals
All_Lines = find_system('ModelName','FindAll','on', 'SearchDepth',1, 'type', 'line');
for i = 1 : length(All_Lines)
outportLineList = get_param(All_Lines(i), 'TraceSourceOutputports');
.
.
%similarly
inportLineList = get_param(All_Lines(i), 'TraceDestinationInputports');
What it does it memics the hilite to source option we have in GUI but it gets you list of objects to play with.

카테고리

도움말 센터File Exchange에서 Modeling에 대해 자세히 알아보기

태그

질문:

2018년 5월 22일

이동:

2024년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by