The body of a parfor-loop cannot contain a break statement.:
The parfor statement works by breaking up iterations of a loop and running these iterations on multiple MATLAB workers. Using break and return statements implies that later iterations of the loop should not run after either of these two statements execute. Therefore, the loop iterations must run in sequence. However, for the parfor loop to be valid, the result of running the successive loop iterations must not depend on the order in which they run.
E.g. the following won't work:
if matlabpool('size') == 0 % checking to see if my pool is already open
matlabpool(2)
end
parfor i=1:10
inv(rand(1000))
break
end
Is there any usual way to imitate a break in a parfor?