List execution order sorted by block execution in Simulink

5 Ansichten (letzte 30 Tage)
Stefan Brunecker
Stefan Brunecker am 27 Jul. 2016
Beantwortet: Jerbin J am 15 Sep. 2023
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?

Antworten (1)

Jerbin J
Jerbin J am 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

Kategorien

Mehr zu General Applications 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