I have inhertited a script that I recently updated to search a data dictionary instead of the base workspace to extract buses and signals. It takes ~4 hours to process ~140 buses /~7000 signals in the data dictionary. When these signals were in the base workspace the processing time was 1.6 seconds.
The profile viewer shows that this line consumes 99% of the script if (exist('ddatasectobj','var')) && (~isempty(find(find(ddatasectobj,'-value','-class','Simulink.Bus'),'Name',buselements{nelements,2})))
Is it a feature of using the data dictionary or is there a better method and I am just missing it?
%iterate through each element to find any nested buses, then
%recursively get all those bus elements... and so on...
for nelements=1:size(buselements,1)
% Remove Bus: prefix from datatype string
buselements{nelements,2} = regexprep(buselements{nelements,2},'^[Bb]us:(\W*|)','');
if (exist('ddatasectobj','var')) && (~isempty(find(find(ddatasectobj,'-value','-class','Simulink.Bus'),'Name',buselements{nelements,2})))
buselements{nelements,5}='bus';
%if haven't already defined, recursively call this function to get all nested buses
if ~sum(strcmp(buselements(1:nelements-1,2), buselements{nelements,2}))
busobjects=[busobjects;getbusdef(slddname,buselements{nelements,2})];
end