title: How to correct "Valid indices for 'variable' are restricted in PARFOR loops" error in matlab
body: <p>I am trying to set up a <code>parfor</code> nested loop in MatLab R2016a as below.</p>
  
  <pre><code>N = size(A,1);
  M = size(v,1);
  in = zeros(N*M,1);
  parfor i=1:N
     for j=1:M
        k = (i-1)*M+j;
        if sqrt(sum((A(i,:)-v(j,:)).^2))&lt;=tol
          in(k) = i;          
        end
     end
  end
  </code></pre>
  
  <p>However, I am getting the following error <strong>Valid indices for 'in' are restricted in PARFOR loops</strong>. Is there some way I can correct this because both arrays <code>A</code> and <code>v</code> are considerably large, over 40,000 rows for <code>A</code> and 8,000 <code>v</code>? The variable <code>tol</code> is 0.0959.</p>