From and Goto block connected block list?

조회 수: 8 (최근 30일)
Ravi
Ravi 2020년 2월 8일
댓글: Ravi 2024년 8월 23일
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에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by