Sliced scalar assignment in parfor

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.

 Accepted Answer

Edric Ellis
Edric Ellis on 11 Dec 2013
Edited: Edric Ellis on 4 Jan 2024
Unfortunately, this is a limitation of PARFOR. The only workaround for MATLAB releases prior to R2019b is not to use scalar expansion like that. The limitation was removed in R2019b.

3 Comments

Thanks, Edric. It's only for sliced variables, then? Temporary variables seem to do scalar expansion okay.
Yes, only sliced variables have the limitation.
Just updated this ancient answer because I just realised the limitation was removed ages ago...

Sign in to comment.

More Answers (0)

Categories

Asked:

on 10 Dec 2013

Commented:

on 4 Jan 2024

Community Treasure Hunt

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

Start Hunting!