MATLAB: How to degug inside a parfor loop

parfor debug breakpoint

When I insert breakpoints inside a parfor loop it is never stopped. In this case how can I debug inside a parfor loop?

Best Answer

You can debug code called from the body of a parfor loop if no parallel pool is open, but unfortunately you cannot debug the body of a parfor loop itself. You can force the parfor loop to run in the desktop MATLAB by appending the optional "number of workers" argument, like so:
parfor (idx = 1:10, 0)
out(idx) = myFcn(idx);
end
With that code, you can set breakpoints inside myFcn.