Transparency issue while adding secondary block

42 visualizzazioni (ultimi 30 giorni)
Kamal
Kamal il 5 Nov 2024 alle 7:34
Risposto: Gayatri il 5 Nov 2024 alle 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.

Risposte (1)

Gayatri
Gayatri il 5 Nov 2024 alle 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

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by