MATLAB: Problem with parfor variable

interp1Parallel Computing Toolboxparfor

Question: I think that the variable A below is a sliced variable but I am unsure how I am violating parfor restrictions – is there any way I can parallelize this?
I receive the error: `Error: The variable A in a parfor cannot be classified.' when I run the following:
parfor j = 1:J
for t = 1:T
A(t+1,j) = interp1(x,V(:,b(t),j),A(t,j),'linear');
end
end
A minimum working example setup just before I invoke the parfor command is:
J = 5;
T = 310000;
A = zeros(310001,5); A(1,:) = ones(1,5);
x = (0.01:0.01:10);
V = repmat(x',[1 3 5]); % V is 1000x3x5
rng('default');
b = randi([1 3],310001,1);

Best Answer

Use the general structure
parfor j=1:J
tA = zeros(T+1,1);
tA(1) = A(1,j);
for t = 1:T
tA(t+1) =..... tA(t)...
end
A(:, j) = tA;
end