Transparency violation error. See Workspace Transparency in MATLAB Statements.

조회 수: 40 (최근 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에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by