EDIT: I have modified the question below. The original example I provided was too simplistic to capture the issue I was facing
Consider the following two examples. The first example works fine:
parfor i = 1:4
for j = 1:3
A(i,j) = i + j;
end
end
However, the second example causes Matlab to complain
B = [1 3 4;1 2 5;2 3 4;1 3 5];
parfor i = 1:4
for j = 1:3
A(i,B(i,j)) = i + j;
end
end
The error is:
The PARFOR loop cannot run due to the way variable 'A' is used.
How do I fix this?