How to determine source block of an input port in Simulink?

조회 수: 47 (최근 30일)
Soham Sinha
Soham Sinha 2021년 8월 31일
댓글: Soham Sinha 2021년 9월 2일
I am writing a Matlab Function Simulink block which has an input. I want to determine the source of the Input port in the Matlab Function and code accordingly. Is there any Simulink API available in Matlab to do that?
If there is, can I get the source block's masks in the Matlab Function block?

답변 (1개)

stozaki
stozaki 2021년 9월 1일
Hi,
1. Get the port handle of the target block. (in this example, MATLAB Funciton)
2. Get the line handle of the connected signal line from the obtained port handle.
3. Get the source block handle of the connection source from the obtained line handle.
4. Get the block properties from the obtained source block handle.
mlBlockPath = 'sample/MATLAB Function';
% get port Handle of MATLAB Function.
mlfPh = get_param(mlBlockPath,'PortHandles');
% get line handle of input signal.
inLine = get_param(mlfPh.Inport,'Line');
% get source block handle(In this case the inport block).
srcBlkH = get_param(inLine,'SrcBlockHandle');
% get source block name
blockName = get_param(srcBlkH,'Name');
  댓글 수: 1
Soham Sinha
Soham Sinha 2021년 9월 2일
Thank you! I tried it but this just gets me the immediate previous block, not the source. For example, the connection goes inside a Subsystem (A) and connected to a block (Block B) inside Subsystem A. I want to get the Block A. However, the above procedure will only give me the Subsystem A.

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

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by