MATLAB: Finding parfor baffling: Can anybody explain to me why this little bit of code works with for,but not with parfor

MATLABparfor

function B = partest
A = 1:4; B = zeros(1,4);
parfor j=1:2
B([j j+2]) = A([j+2 j]);
end
The two bits of the loop access different bits of B, so there should be some way of doing this. My actual application involves large cell arrays, for which something similar holds for the function within the loop.

Best Answer

A = reshape(1:4,2,2);
B = zeros(2);
parfor j=1:2
B(j,:) = A(j,end:-1:1);
end
Related Question