1
votes

I have some data that is curve fitting nicely using custom equation from cftool. The equation is: y = aexp(-bx)+c. Is there any way to make this same equation available from the command line? For instance using fit command and exp1 gives following results:

f = fit(time,T102,'exp1')

f = 

     General model Exp1:
     f(x) = a*exp(b*x)
     Coefficients (with 95% confidence bounds):
       a =      0.0726  (0.0717, 0.0735)
       b =  -1.263e-05  (-4.171e-05, 1.645e-05)

However the form of this equation does not fit my data well. I need to have the equation as f(x) = aexp(bx) + c. I am aware that I can get it from cftool but I have many different sets of data to curve fit (~30) and I just want a, b, and c returned from by MATLAB in the custom equation f(x) = aexp(bx) + c.

1

1 Answers

1
votes

I ended up finding my answer using information from following link: https://www.mathworks.com/help/curvefit/fit.html

  1. Create a matlab function that contains custom equation for fit

    function y = CustomCurveFitFunction(x,a,b,c)

    y = aexp(-bx) + c;

    end

  2. Call the function in the following manner from MATLAB

    ft = fittype('CustomCurveFitFunction(x, a, b, c)');

    f = fit(time, y, ft);