List execution order sorted by block execution in Simulink
5 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Jerbin J
2023-9-15
% 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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!