How to know which inport-block belong to which From-Block ?

2 views (last 30 days)
Hi everyone,
This is an exemple of my question. Imagine that i have a lot of subsystems and in the main-system or in the subsystem itself there are too many of From-Blocks.
my question is: how to detect the the selected signale in the subsytem belong to which From-Block. In another way which inport-Block belong to which From-Block
from-Inport.PNG sub.PNG
This will work only if the Inport-Block connected in sorted way with From-Block
for exemple: [A]-Block will be detected as From, [B]-Block will be detected as From1 and Inport-Block will be detected as " 1 " , if i run my code it will work fun.
but in case that [A]-Block will be detected with From10 or another number. so how can i know programmatically that selected signal belong to which From-Block
Hier is my try:
% Select Signal data from the Simulink Model
selectObj = find_system(gcs,'findall','on','selected','on','parent',gcs); % get the selected object
parent_handle = get_param(selectObj,'SrcBlockHandle'); % get parent handle (in this case Inport-Block)
block_type = get_param(parent_handle,'BlockType'); % get the block Type
parent_path = get_param(parent_handle,'Parent'); % get the path of the parent (in this case subsystem)
parent_path=strsplit(parent_path,'/')
parent_path(end)=[];
parent_path = strjoin(parent_path,'/') % get the path of parent parent system (in this case main system)
Blocks_From = find_system(parent_path,'SearchDepth',1,'BlockType','From') % find all existed From-Blocks
port_nr = str2num(get_param(parent_handle,'Port')) % get the number of Inport-Block
signal_name = get_param(Blocks_From{port_nr,1},'GotoTag') % get the name of the from-Block
I hope someone can help
thank you in advance

Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!