Clear Filters
Clear Filters

List execution order sorted by block execution in Simulink

8 views (last 30 days)
I need to get a list of all blocks in a Simulink model in order in which they are executed. I know I can use slist but the blocks are only ordered within each SubSystem. So if I have two Subsystems A and B with sorted execution order 0:1 and 0:2 then blocks in A might have execution order 2:x and blocks in B 1:x. Then slist lists the blocks in B before A. Now I need a list that orders blocks in A before B. Is that possible?

Answers (1)

Jerbin J
Jerbin J on 15 Sep 2023
% Get model name
modelName = bdroot(gcs);
% Empty array for execution order
executionOrder = [];
% Turn off data logging
mdlsignals = find_system(gcs,'FindAll','on','LookUnderMasks','all','FollowLinks','on','type','line','SegmentType','trunk');
portHandle = get_param(mdlsignals,'SrcPortHandle');
for i=1: length(portHandle)
set_param(portHandle{i},'datalogging','off')
end
% Get blocks by execution order
sortedList = get_param(modelName, 'SortedList');
%% Logic
for ii = 1:length(sortedList)
handl = sortedList(ii);
% Get block name
blkName = string(get_param(handl,'Name'));
% Get block type
blkType = get_param(handl,'BlockType');
% Check if block is "Constant"
if strcmp(blkType,'Constant') == 0
% Form the array
executionOrder = [executionOrder;blkName];
end
end

Categories

Find more on Programmatic Model Editing 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!