Transparency issue while adding secondary block

42 visualizaciones (últimos 30 días)
Kamal
Kamal el 5 de Nov. de 2024 a las 7:34
Respondida: Gayatri el 5 de Nov. de 2024 a las 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.

Respuestas (1)

Gayatri
Gayatri el 5 de Nov. de 2024 a las 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

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by