title: Using Parsave inside parfor loop - saves only my last variable result
body: <p>This is a simplified version of my code. What i want to obtain is a variable1 - row vector contained in result.mat. Problem is that parsave - saves only one result, the last one from the 10th iteration. What can i do to save all results in one vector (in variable1) inside the parfor loop? </p>
  
  <pre><code>parfor ii = 1:10
  
      [variable1, variable2] = MyFunction(~,~,ii);
  
      parsave('result.mat',variable1, variable2)
  
  end
  
  function parsave(filename, varargin)
  
  narginchk(2, Inf);
  
  nargoutchk(0, 0);
  
  for I = 2:nargin
  
      varname = genvarname(inputname(I));
      eval([varname ' = varargin{' num2str(I-1) '};'])
  
      if (I == 2)
          save(filename, varname)
      else
          save(filename, varname, '-append')
      end
  
  end
  </code></pre>