When controlArg
is false, optionalArg
is undefined. I guess MATLAB does not trust you that controlArg
will always be false (and by that, I mean it has no mechanism to deduce it, although for the code above, a human may think it is obvious). Thus, it cannot guarantee that no parfor
iteration needs to know optionalArg
at this point of your code:
if controlArg
tempNum = tempNum * optionalArg;
end
For a quick fix, define optionalArg
without the surrounding if clause -- you check controlArg
again before you use it anyway. Alternatively, try replacing optionalArg
by 10*controlArg
(or all three lines by some mathematical expression that maps 0
(false) to 1 and 1
(true) to your desired value of optionalArg
, e.g. tempNum = tempNum * (controlArg*9+1);
).
btw: Maybe you can tell a bit more about the actual problem (not necessarily in this question). The output array above can be produced by one line of code or two, and I guess one of the advantages of MATLAB, vectorised calculation of many similar operations at once (without explicit parallelisation) can be applied to your problem as well (i.e. you might not need three levels of for
loops.