Transparency issue while adding secondary block
42 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Gayatri
2024-11-5,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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!