Borrar filtros
Borrar filtros

Extracting bus elements and their signals from a data dictionary has very slow performance.

15 visualizaciones (últimos 30 días)
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

Respuestas (1)

Ashutosh Thakur
Ashutosh Thakur el 26 de Jun. de 2024 a las 10:35
Hi Dawn,
I understand that you are trying to search through a data dictionary but are facing slow performance while executing these queries. The increase in processing time between accessing the base workspace and a data dictionary in Simulink is likely due to the overhead associated with these queries. As you mentioned, a particular query consumes 99% of the overall time during the execution of your script.
The following steps can be followed to improve performance:
Cache Repeated Searches:
Bulk Data Retrieval:
  • If you have a bulk of data, try executing the query to get dictionary data without using loops, and then store this data in a MATLAB variable. For example, the following sample code will retrieve all the Simulink.Bus objects from the data dictionary section object passed to it:
% ddSectObj is the Simulink.data.dictionary.Section object
find(ddSectObj, '-value', '-class', 'Simulink.Bus').
Use Parallel Computing:
I hope this helps you in improving the performance.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by