It seems to be related to my use of a try-catch. My code is something like:
errors = 0;
%K,N,S, MAX, etc defined elsewhere
parfor i=1:MAX
p = zeros(K,N);
a = zeros(K,N);
rate = zeros(1,S);
while (true)
try
[ p, a, rate ] = someFunction();
break;
catch ME
errors = errors +1;
end
end
end
Basically, someFunction() could throw an error, then try again. If I leave the catch empty, it works perfectly, and while I don't really need to record how many errors there were, it was useful initially and I did have other lines in there.
Even though it now works for what I need today, I'd still love to know why this error is occurring in case I ever need to do something in the catch.