How to determine source block of an input port in Simulink?
47 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!