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.
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;
|
b = 0;
|
For more information, see Temporary Variables.