Transparency violation error. See Workspace Transparency in MATLAB Statements.

64 次查看(过去 30 天)
When I execute the below code I get the title error. Can someone explain the error and how to fix it?
N = 2:2:4;
parfor j = 1:length(N)
x = (6.2831853071795865/N(j))*(0:N(j)-1)'; FIM1 = 2*x;
save(sprintf('FIM1_%d.mat',N(j)),'FIM1');
end

采纳的回答

Mandar
Mandar 2022-8-19
The use of "save" function inside a parfor is not supported because in general MATLAB cannot determine which variables from the workspace, hence, it shows a 'Transperency violation error'. The possible workaround is to move the call to the "save" function in a separate used defined function and make a call to it from 'parfor' loop. Pass any variables that are to be saved as arguments to the function. That way MATLAB can determine which ones will be saved and transparency is not violated.
For example, create a used defined function "parsave.m" ans save on the same path.
function parsave(fname, x)
save(fname, 'x')
end
Then, execute the following code.
N = 2:2:4;
parfor j = 1:length(N)
x = (6.2831853071795865/N(j))*(0:N(j)-1)'
FIM1 = 2*x
% save(sprintf('FIM1_%d.mat',N(j)),'FIM1');
parsave(sprintf('FIM1_%d.mat',N(j)),'FIM1');
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by