title: Store all iteration loop results in a matrix
body: <p>I have a code that basically selects some data segements and performs some calculations on these data segments (regression lines, so I look at the slope and the intercept of the resgression lines). The code works fine and at the end it displays in the Command window the results of all the loop iterations but it only sotres in a matrix (called final) the last loop iteration results. Basically I would like to have all the results in a matrix. </p>
  
  <p>Here i attach the code: </p>
  
  <pre><code>Data = csvread(inputFile);
  
  for i=1:max(L)
  try
  B = [ones(length(result{i}),1) result{i}(:,1)] \ result{i}(:,2);
  catch
      continue 
  end
  
  
  intercept = B(1);
  slope  = B(2);
  position  = (slope.*result{i}(end,1)+intercept)-(slope .*result{i}(1:1)+intercept);
  time = result{i}(end,1)-result{i}(1:1);
  
  final =[slope, intercept, position, time] 
  
  end
  </code></pre>
  
  <p>At the moment I get the result of each loop in the command window. So i obtain something like this:</p>
  
  <pre><code>final =
  
     4.6607  -27.7973    0.0621    0.0133
  
  
  final =
  
     -0.0647   -0.1299   -0.0517    0.7992
  
  
  final =
  
     -9.0676   74.6981   -0.0604    0.0067
  
  
  final =
  
     0.3176   -3.2234    0.0698    0.2198
  
  
  final =
  
     0.2153   -2.3666    0.0631    0.2930
  
  
  final =
  
     -5.1864   45.6418   -0.2072    0.0400
  
  
  final =
  
     -1.0881    9.1772   -0.0797    0.0733
  
  
  final =
  
     -0.5416    4.3386   -0.1605    0.2964
  
  
  final =
  
     -4.4898   39.8786   -1.2409    0.2764
  
  
  final =
  
     -3.0985   26.3052   -0.0619    0.0200
  
  
  final =
  
     2.0871  -24.2849    0.0208    0.0100
  
  
  final =
  
     1.0060  -15.6203    0.0067    0.0067
  </code></pre>
  
  <p>How can I get all this in a matrix?</p>
  
  <p>Thanks in advance!!</p>