Explanation

In a parfor-loop, temporary variables are cleared at the beginning of each iteration. These variables must be set inside the body of the loop before they are used, so that their values are defined separately for each iteration. A variable that is set outside the parfor-loop has no effect on a temporary variable with the same name.


Suggested Action

Make sure that any temporary variable is set inside the parfor-loop before it is used. For readability, consider renaming variables outside the loop that have the same names as the temporary variables. In this example, the original version tries to display the temporary variable a in the parfor-loop before it is assigned a value. The revised version avoids the error by setting a first.

Original Revised
a = 0;
parfor i = 1:10
    disp(a)
    a = i;
end
disp(a)
  b = 0;
parfor i = 1:10
    a = i;    
    disp(a)   
end
disp(b)

For more information, see Temporary Variables.