I am wondering how can I easily access the global variable in calling a function within a parfor loop? For example the sample code is as follows,
global a
a = 132.1;
A = [0, 0, 0];
for i=1:3
A(i) = test(i);
end
And the test function is
function f = test(v)
global a
f = a+v;
The code should be correct in this format, however, if I change for to parfor, it arises problem. I think the major problem is the global variable a. So how can I modify the code? Although in this example, the modification is easy and no need for parfor, but my real code is really complicated, the problem gets down to the same one.