Transparency violation error. See Workspace Transparency in MATLAB Statements.

64 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Mandar
Mandar el 19 de Ag. de 2022
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

Más respuestas (0)

Categorías

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

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by