From and Goto block connected block list?

10 Ansichten (letzte 30 Tage)
Ravi
Ravi am 8 Feb. 2020
Kommentiert: Ravi am 23 Aug. 2024
how to find connected Corresponding From blocks list in Goto block? (Using mscript)
Similarly for From Block?

Akzeptierte Antwort

Sameer
Sameer am 23 Aug. 2024
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!

Weitere Antworten (0)

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by