User`s guide

Convert Nested for-Loops to parfor
2-49
M1 = magic(5);
for a = 1:5
parfor b = 1:5
M2(a,b) = a*10 + b + M1(a,b)/10000;
end
end
M2
In this case, each iteration of the outer loop in MATLAB, initiates a parfor-loop. That
is, this code creates five parfor-loops. There is generally more overhead to a parfor-
loop than a for-loop, so you might find that this approach does not perform optimally.
More About
“Nesting and Flow in parfor-Loops” on page 2-15