title: error with 'parfor' in matlab
body: <p>i have written a function in matlab, which is to calculate a cost function for an array:</p>
  
  <pre><code>  function [F1val, Com]=F1(Community,NeighMat)  
          global FlattedAdjMat;
          Com=zeros(numel(Community),3);
          Com(:,1)=Community';  % The First row of Com= Community's Nodes  
          % Calculating INTERNAL Edges of Community  
              for j=1:numel(Com(:,1))
                  Com(j,2)=sum(FlattedAdjMat((Community),Com(j,1)));% Internal Degrees of Node j            
              end
          F1val=(nansum(Com(:,3)./((Com(:,2)+Com(:,3)))));
    end
  </code></pre>
  
  <p>But i have 2 problem with the line <code>Com(j,2)=sum(FlattedAdjMat((Community),Com(j,1)))</code>, </p>
  
  <ol>
  <li><p>when i try to execute it in parallel using <code>parfor</code>:</p>
  
  <pre><code>parfor iii=1:5
      [z,p]=F1(Community,NeighMat)
  end
  </code></pre>
  
  <p>this error occurs in the line: <code>Index exceeds matrix dimensions</code> 
  while in normal case(not Parallel) there is no problem</p></li>
  <li>it is very time consuming and slow down the speed.</li>
  </ol>
  
  <p><code>NeighMat</code> is a weighted adjacency matrix, 
  <code>Community</code> is an array of the matrix indexes,
  <code>FlattedAdjMat</code> is adjacency matrix.</p>
  
  <p>whould you please help me?</p>
  
  <p><strong>sample data:</strong></p>
  
  <pre><code>for ii=1:10
     NeighMat{ii}=randi(10,1,10)
  end
  
  Community=[1,5,6,8,9];`
  
  global FlattedAdjMat
  FlattedAdjMat=randi([0,1],10,10)
  </code></pre>