Clear Filters
Clear Filters

From and Goto block connected block list?

18 views (last 30 days)
Ravi
Ravi on 8 Feb 2020
Commented: Ravi on 23 Aug 2024 at 11:23
how to find connected Corresponding From blocks list in Goto block? (Using mscript)
Similarly for From Block?

Accepted Answer

Sameer
Sameer on 23 Aug 2024 at 9:16
Hi Ravi
From my understanding, you want to find the corresponding connected blocks between “From” and “Goto” blocks in a Simulink model using a MATLAB script.
We can achieve this by leveraging the “Simulink API”. For “Goto” blocks, we identify all “From” blocks that share the same tag by searching the model using the “GotoTag” parameter. Similarly, for “From” blocks, we locate all “Goto” blocks with matching tags.
Here's how you can do it:
Finding Corresponding “From” Blocks for Each “Goto” Block
% Load your model
modelName = 'your_model_name';
load_system(modelName);
% Find all Goto blocks
gotoBlocks = find_system(modelName, 'BlockType', 'Goto');
% Initialize a structure to hold the result
gotoFromMapping = struct();
for i = 1:length(gotoBlocks)
% Get the tag of the Goto block
gotoTag = get_param(gotoBlocks{i}, 'GotoTag');
% Find all From blocks with the same tag
fromBlocks = find_system(modelName, 'BlockType', 'From', 'GotoTag', gotoTag);
% Store the result
gotoFromMapping.(gotoTag) = fromBlocks;
end
disp(gotoFromMapping);
Finding Corresponding “Goto” Blocks for Each “From” Block
% Find all From blocks
fromBlocks = find_system(modelName, 'BlockType', 'From');
% Initialize a structure to hold the result
fromGotoMapping = struct();
for i = 1:length(fromBlocks)
% Get the tag of the From block
fromTag = get_param(fromBlocks{i}, 'GotoTag');
% Find all Goto blocks with the same tag
gotoBlocks = find_system(modelName, 'BlockType', 'Goto', 'GotoTag', fromTag);
% Store the result
fromGotoMapping.(fromTag) = gotoBlocks;
end
disp(fromGotoMapping);
Hope this helps!

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!