From and Goto block connected block list?

9 次查看(过去 30 天)
how to find connected Corresponding From blocks list in Goto block? (Using mscript)
Similarly for From Block?

采纳的回答

Sameer
Sameer 2024-8-23
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!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by