Transparency violation error. See Workspace Transparency in MATLAB Statements.

40 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Mandar
Mandar le 19 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by