I'm attempting to convert some code to use a parfor, and have run into difficulty. A simplified example is given below, which doesn't work. I have read the documentation and lots of answers, but nonetheless can't seem to work it out.
% Preallocate array
var1 = zeros(5);parfor i = 1:5 for j = 2:6 var1(j, :) = j; endend
Preallocating the arrays within the parfor gives no errors, but I don't understand why this works but the initial example doesn't. Could someone please put me out of my misery and explain this, or point me to the right bit of documentation? Thanks
parfor i = 1:5 % Preallocate array var1 = zeros(5); for j = 2:6 var1(j, :) = j; endend
Best Answer