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
댓글 수: 0
채택된 답변
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
추가 답변 (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!