title: Custom Curve Fitting in MatLab
body: <p>I am trying to define a custom Curve Fit in MatLab. The curve which I am trying to fit to is as follows:</p>
  
  <pre><code>A*exp(B*x)+C
  </code></pre>
  
  <p>The reason this fit is needed is because my data decays exponentially, however this data does not approach zero (in this data set, the curve should decay and approach some number above zero). Using fittype('exp2') is also not an option because it overfits the data (curves upwards towards the end when it should remain flat somewhere above 0). I define the fit type using the following code:</p>
  
  <pre><code>ft = fittype('(A*exp(B*x)) + C','coefficients', {'A', 'B', 'C'});
  </code></pre>
  
  <p>However, when I try to fit data to this curve I get the following error message: </p>
  
  <p>"Error using cfit/subsref>iDotReference (line 66)
  Name is neither a coefficient or a problem parameter.</p>
  
  <p>Error in cfit/subsref (line 19)
  out = iDotReference( obj, currsubs );"</p>
  
  <p>I can't figure out exactly what MatLab is complaining about in this case. Sometimes, for reasons I do not know, the code will run but the fit is just terrible. Am I doing something wrong here? Is this the best way to an exponential that decays to some above 0 value?</p>
  
  <p>The following code is how I try to run my fit:</p>
  
  <pre><code>[cf, gof] = fit(time', testArray', fittype);
  </code></pre>