Transparency issue while adding secondary block

42 Ansichten (letzte 30 Tage)
Kamal
Kamal am 5 Nov. 2024 um 7:34
Beantwortet: Gayatri am 5 Nov. 2024 um 8:23
I'm attempting to generate Simscape models using a parfor loop for parallel processing, but this results in a transparency violation error when adding blocks. The error points to the 'PreCopyFcn' callback in the masks of all Simscape blocks. I tried loading the libraries within the parfor loop, but this approach didn’t resolve the issue.

Antworten (1)

Gayatri
Gayatri am 5 Nov. 2024 um 8:23
Hi Kamal,
You can use 'parfeval' to avoid the transparency violation error. Here is an example:
1. Define a function to create Simscape model.
function foo(modelName)
ModelName = modelName; % Set up the model
proj = new_system(ModelName); % Create a new system
open_system(ModelName); % Open the new model
% Add blocks
add_block('simulink/Sinks/Scope', [ModelName '/myScope']);
add_block('fl_lib/Thermal/Thermal Elements/Thermal Mass', ...
[ModelName '/myblock'], 'Position', [250 135 300 200]);
% Save the system
save_system(ModelName);
close_system(ModelName);
end
2. Call this function using parfeval:
>> f = parfeval(@foo, 0, 'Model_1');
The parfeval function avoids issues related to callbacks and transparency by executing each instance of foo independently in parallel workers.
Please refer the below documentation for parfeval:https://www.mathworks.com/help/matlab/ref/parfeval.html

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by