How to find path of the signal source from its name?

14 ビュー (過去 30 日間)
Vick
Vick 2022 年 3 月 29 日
編集済み: Abhaya 2024 年 9 月 6 日
Above is the subsystem of my big model, in this I've 2 outports and the path of the subsytem is "MyModel/handle_error/apply_linear", this outports is going to my root of the model "MyModel". If i press "highlight to source" in my required signal at root path, it is taking me to my source.
How to get this via matlab command? Like if i give a signal name "final_output", the command should be able to give path of source "MyModel/handle_error/apply_linear"

回答 (1 件)

Abhaya
Abhaya 2024 年 9 月 6 日
編集済み: Abhaya 2024 年 9 月 6 日
Hi Vick,
To trace the origin of a signal in a Simulink model, you can utilize theSrcBlockHandleandSrcPortHandleparameters with MATLABget_paramfunction.
Please follow the given steps to find the source of a signal from its handle.
  • Select the block from which you want to trace the signal's source.
  • Refer to the code given below to trace the signal to the origin.
function src=traceSignalFun(blockHandle)
portHandles = get_param(blockHandle, 'PortHandles');
src=getfullname(blockHandle);
if isfield(portHandles, 'Inport')
line = get_param(portHandles.Inport(1), 'Line');
if line ~= -1 % Check if there is a connected line
% Get the source block of the line
srcBlockHandle = get_param(line, 'SrcBlockHandle');
srcPortHandle = get_param(line, 'SrcPortHandle');
% Get the full name of the source block
srcBlockName = getfullname(srcBlockHandle);
% Get the source port number
srcPortNumber = get_param(srcPortHandle, 'PortNumber');
blockType = get_param(srcBlockHandle, 'BlockType');
if strcmp(blockType, 'SubSystem')
% Get the blocks inside the subsystem
outPorts=find_system(srcBlockHandle,'SearchDepth', 1, 'BlockType', 'Outport');
src=traceSignalFun(get_param(outPorts(srcPortNumber),'Handle'));
else
src=getfullname(srcBlockName);
end
end
end
end
%call the function using handle to the selected block
source=traceSignalFun(gcbh);
disp(source);
For further information, please refer to the MATLAB documentation for get_param’ function,
Hope this helps.

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by