title: How to use `crossval` in matlab for a Leave one Out Validation method
body: <p>I have been reading the documentation: <a href="http://www.mathworks.com/help/stats/crossval.html" rel="nofollow noreferrer">here</a> and <a href="http://www.mathworks.com/help/stats/cvpartition.html" rel="nofollow noreferrer">here</a> but it's really unclear for me and I don't see how to use pratically <code>crossval</code> to do a leave one out cross-validation.</p>
  
  <pre><code>vals = crossval(fun,X)
  vals = crossval(fun,X,Y,...)
  mse = crossval('mse',X,y,'Predfun',predfun)
  mcr = crossval('mcr',X,y,'Predfun',predfun)
  val = crossval(criterion,X1,X2,...,y,'Predfun',predfun)
  vals = crossval(...,'name',value)
  </code></pre>
  
  <p>I really don't understand the <code>fun</code>part.</p>
  
  <p>I have estimatimate chlorophyll rate with different index. Then I have done a linear regression between those index and the field taken chlorophyll rate. Now I want to validate them, one of my estimation is a column with 22 entries, so I want to use 21 of them as trainee and 1 as a test, and do 22 loops so that all the data have been used as test. 
  But I don't where should I put the regression model? If my regression is Y=aX+b,
  do I re-use the a and b calculated before for the train part, or do I do a new linear regression with the train part then see what's the test will be with that? 
  I am not sure I totally understood how to make a leave one out model.</p>
  
  <p>Then I want to know the result of the test by calculating the RMSE (and maybe the R²).</p>
  
  <p>How do I code that using <code>crossval</code>?</p>
  
  <p>I saw the answer to the question <a href="https://stackoverflow.com/questions/31093983/leave-one-out-crossvalind-in-matlab">here</a> but I don't have access to the <code>crossvalind</code> fonction with my license.</p>