title: extracting data from for loop matlab
body: <p>the problem i'm trying to solve here is how do i extract the data of x1,y1,x2,y2 as i have 5 sets of those data due to 5 planes? the data im getting in the workspace is only the last data, which is challenge for me to retrieve the data needed</p>
  
  <pre><code> j = 2;
  
   for i = 1 : 5 % number of planes( 3D matrix ) 
      x1 = P(:,1,i); % x value
      y1 = P(:,2,i); % y value
  
      valid1 = y1 &gt; 0;
      valid_fzn1 = y1(valid1);
      valid_time1 = x1(valid1);
  
      x2 = P(:,3,i);
      y2 = P(:,4,i);
  
      valid2 = y2 &gt; 0;
      valid_fzn2 = y2(valid2); % getting data more than zero
      valid_time2 = x2(valid2); % getting data more than zero
  
      figure(j)
      subplot(2,1,1)
      plot(valid_time1,valid_fzn1,'b.')
      title('Fzn vs time(Left Leg)')
      xlabel('time(s)')
      ylabel('Fzn(N)')
      hold on
  
      subplot(2,1,2)
      plot(valid_time2,valid_fzn2,'b.')
      title('Fzn vs time(Left Leg)')
      xlabel('time(s)')
      ylabel('Fzn(N)')
      hold on
  
  
      j = j + 1;
      i = i + 1;
  end
  </code></pre>