It is most likely the line
dated.MeanIV = double(MeanIV)
that is the problem.
parfor
will try to "slice" MeanIV
, i.e. send individual rows to different workers. However, at the dated
line, you need the entirety of the array.
Move the line after the end
of the parfor
loop, and it will work.