MATLAB: Sliced scalar assignment in parfor

parallelParallel Computing Toolboxparforpct

The following code
A=rand(10);
parfor j=1:10
A(:,j)=1;
end
gives me the following error
Error using test (line 5)
Subscripted assignment dimension mismatch.
Caused by:
Subscripted assignment dimension mismatch.
It seems that you cannot do scalar assignment with parfor sliced variables? If not, is this documented somewhere? I know sliced variables must maintain a constant shape, but scalar assignment does not violate this.

Best Answer

Unfortunately, this is a limitation of PARFOR. The only workaround for now is not to use scalar expansion like that.