title: Cell arrays in MATLAB using parfor
body: <p>I need to parallelize a script in MATLAB. I have a cell array that I am returning values to. But, MATLAB does not accept the way that I structure the parallelization of my script. </p>
  
  <pre><code>N_h = 4;
  N_r = 6;
  N_s = 20;
  
  P{1:N_h, 1} = zeros(N_s, N_r);
  
  workers = 4;                                % number of cores (workers) for parallel computing 
  multicore = parpool('local', workers);      % open multiple workers (cores) for parallel computation 
  
  for h = 1:1:N_h
      for r = 1:1:N_r
          parfor s = 1:N_s
              P{h,1}(s,r) = some function ... 
          end
      end
  end
  
  delete(multicore);                      % delete multiple workers (cores) opened for parallel computation
  </code></pre>
  
  <p>MATLAB responds that the variable <code>P</code> is indexed in a way that is incompatible with <code>parfor</code>. How should I change my script?</p>