I am trying to define a custom Curve Fit in MatLab. The curve which I am trying to fit to is as follows:
A*exp(B*x)+C
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:
ft = fittype('(A*exp(B*x)) + C','coefficients', {'A', 'B', 'C'});
However, when I try to fit data to this curve I get the following error message:
"Error using cfit/subsref>iDotReference (line 66) Name is neither a coefficient or a problem parameter.
Error in cfit/subsref (line 19) out = iDotReference( obj, currsubs );"
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?
The following code is how I try to run my fit:
[cf, gof] = fit(time', testArray', fittype);