title: Parfor in Matlab
body: <p>I'm trying to run this loop as a parfor-loop:</p>
  
  <pre><code>correlations = zeros(1,N);   
  parfor i = 1:(size(timestamps,1)-1)
      j = i+1;
      dts = timestamps(j) - timestamps(i);
      while (dts &lt; T) &amp;&amp; (j &lt;= size(timestamps,1))
          if dts == 0 &amp;&amp; detectors(i) ~= detectors(j)
              correlations(1) = correlations(1) + 2;
          elseif detectors(i) ~= detectors(j)
              dts = floor(dts/binning)+1;
              correlations(dts) = correlations(dts) + 1;
          end
          j = j + 1;
          if j &lt;= size(timestamps,1)
              dts = timestamps(j) - timestamps(i);
          end
      end
  end
  </code></pre>
  
  <p>Matlab gives me the following error:</p>
  
  <pre><code>Error: File: correlate_xcorr.m Line: 18 Column: 17
  The variable correlations in a parfor cannot be classified.
  See Parallel for Loops in MATLAB, "Overview".
  </code></pre>
  
  <p>Line 18 is the following:</p>
  
  <pre><code>correlations(1) = correlations(1) + 2;
  </code></pre>
  
  <p>I can not understand why this shouldn'n be possible. The final value of correlations doesn't depend on the order in which the loop is executed, but only dts and detectors. I found similar examples in the documentation which work fine.</p>
  
  <p>Why can't Matlab execute this code and how can I fix it?</p>