In my for loop, I set a matrix variable ga to save the results of every loop.
But when I change the for loop to the parfor loop (to accelerate), there is a warning as follows:
And when I run the code, I get another error:
The code is:
R=100;
alpha_set = [1,2,3,4,5]; % This is an index set
ga = zeros(2,5); % to save results of addition
parfor h=1:R
[A1,A2] = random_sample(A,0.6);
...
for ai=1:5
alpha = alpha_set(ai);
ga(1,ai) = ga(1,ai) + T_lower(A2,alpha)/R;
ga(2,ai) = ga(2,ai) + T_upper(A2,alpha)/R; % accumulation
end
end
T_upper and T_lower are both functions which return numbers.
I want to sum the returns of the two functions, and save the values under different index alpha to different positions of ga, so ga should be classified as reduced variable, shouldn't it? (While Matlab cannot classify it.)
How can I debug the code and make parfor run successfully?

