MATLAB parfor broadcast variable has wrong value
<p>In this minimal executable piece of code:</p>

<pre><code>a = [];
workers = parpool('local',4);
someboolean = false;
parfor i = 1:4
    if someboolean % broadcast variable
        b = a(i); % ERROR
    else
        b = 0;
    end
end
</code></pre>

<p>... the value of someboolean is 'true' and the invalid line is executed resulting in the following error:</p>

<blockquote>
  <p>Error using bugscript (line 4)<br>
      Index exceeds matrix dimensions.</p>
</blockquote>

<p>The line number refers to the last nonparallel line and if the  <code>b = a(i)</code> assignment is removed the error disappears.</p>

<p>I have not been able to find others on the internet suffering from the same problem. Can anyone explain what is going on? I am using MATLAB R2015a.</p>