User`s guide

2 Parallel for-Loops (parfor)
2-32
Reduction Variables
MATLAB supports an important exception, called reductions, to the rule that loop
iterations must be independent. A reduction variable accumulates a value that depends
on all the iterations together, but is independent of the iteration order. MATLAB allows
reduction variables in parfor-loops.
Reduction variables appear on both side of an assignment statement, such as any of the
following, where expr is a MATLAB expression.
X = X + expr X = expr + X
X = X - expr See Associativity in Reduction Assignments
in “Further Considerations with Reduction
Variables” on page 2-34
X = X .* expr X = expr .* X
X = X * expr X = expr * X
X = X & expr X = expr & X
X = X | expr X = expr | X
X = [X, expr] X = [expr, X]
X = [X; expr] X = [expr; X]
X = {X, expr} X = {expr, X}
X = {X; expr} X = {expr; X}
X = min(X, expr) X = min(expr, X)
X = max(X, expr) X = max(expr, X)
X = union(X, expr) X = union(expr, X)
X = intersect(X, expr) X = intersect(expr, X)
Each of the allowed statements listed in this table is referred to as a reduction
assignment, and, by definition, a reduction variable can appear only in assignments of
this type.
The following example shows a typical usage of a reduction variable X:
X = ...; % Do some initialization of X