This error occurs when multiple MATLAB workers attempt to access the matlabprefs.mat file simultaneously. Here is a sample code to reproduce this issue:
function parTest
if matlabpool('size')==0
matlabpool('open');
end
parfor i=1:10
pause(randn(1));
setpref('parTest','test','test');
end %parfor
end %function parTest
To avoid this problem, set preferences using "pctRunOnAll" , before the parfor loop.
function parTest
if matlabpool('size')==0
matlabpool('open');
end
pctRunOnAll setpref('parTest','test','test');
parfor i=1:10
...parfor statements go here...
end
end %function parTest
Alternatively, the problem can be avoided by increasing the pause time from "pause(randn(1))" to "pause(randn(i/100))" , where 'i' is the parfor counter variable.