1
votes

I have a table with 2 column, c1 and c2 in Matlab. I want to use the Curve Fitting Tool to fit the exponential equation into my data.

Right now I have this in my code: cftool(c1,c2);

this code is going to open cftool and fit the polynomial curve! However I want it as an Exponential curve! How can I do that?

2

2 Answers

1
votes

Is that what you want?

f = fit(x,y,'exp1');

You can also customize:

myfit = fittype('a*u+b*exp(n*u)',...
            'problem','n',...
            'independent','u');

to use f=fit(x,y,'myfit'); You can read about it here and here

0
votes

The key is to have the data to be fit in your workspace and choose the X data and Y data first. Then the dropdown menu will show "Exponential" as an option. From this documentation page:

  1. Open the Curve Fitting app by entering cftool. Alternatively, click Curve Fitting on the Apps tab.
  2. In the Curve Fitting app, select curve data (X data and Y data, or just Y data against index).
    Curve Fitting app creates the default curve fit, Polynomial.
  3. Change the model type from Polynomial to Exponential.

To see the code used by cftool for fitting your data, select File > Generate Code after you've configured all of the options and are satisfied with the results. You can then use and modify this code for your application instead calling cftool. In the case of a simple exponential fit, it looks like the fit function is used with options specified via fittype and fitoptions.