EzyFit Frequently Asked Questions

EzyFit Frequently Asked Questions



If you have a question which is not answered here, or a suggestion on how you would improve this section, please feel free to send an e-mail to the author, moisy@fast.u-psud.fr.

  1. Why using EzyFit instead of the standard Matlab's "Basic Fitting" tool?
  2. Why using EzyFit instead of MathWorks' "Curve Fitting Toolbox"?
  3. I have two curves in my figure, and I want to fit only the second one!
  4. Why there is no EzyFit menu in my figure?
  5. I want to fit only part of my data!
  6. I want the fitted parameters of my data, but whithout drawing the curve!
  7. How to change the default color/style of the fits?
  8. What are the "initial guesses"?
  9. What means "(lin)" or "(log)" in the equation box?
  10. Can I extrapolate the fitted curve further than my data range?
  11. Where are stored the values of the fitted parameters?
  12. Can I save a fit equation?


  1. Why using EzyFit instead of the standard Matlab's "Basic Fitting" tool?

    Well, the "Basic Fitting" looks nice, but it only fits polynomials.

  2. Why using EzyFit instead of MathWorks' "Curve Fitting Toolbox"?

    MathWorks' "Curve Fitting Toolbox" does much more than EzyFit. But EzyFit is simpler (you can make it work in 1 minute), and it is free. For most usual problems, EzyFit will surely do the job.
    Note that these two toolboxes cannot be used simultaneously. See the Known Software Problems section.

  3. I have two curves in my figure, and I want to fit only the second one!

    First select the curve you want to fit using the pointer (mouse), and then fit it.

  4. Why there is no EzyFit menu in my figure?

    Type efmenu to have the EzyFit menu in your current and all subsequent figures. You may also type
    efmenu install
    to have the EzyFit menu by default in all your figures (this will automatically run efmenu at each Matlab restart).

  5. I want to fit only part of my data!

    Use selectfit for this. First plot some sample data,
    plotsample powco
    (a power law with an exponential cutoff), then fit the upper part with a power law,
    selectfit power
    You now have to draw a polygon around the part of the data you want to fit

    Once you are done, close the polygon by clicking the right mouse button. Now the program waits for you to draw a new polygon if you are not satisfied. If you are satisfied, right-click again.

    You may escape the polygon procedure by pressing the ESC key.

  6. I want to get the fitted parameters of my data, but whithout drawing the curve!

    If your data are X,Y, you just obtain the fitted parameters by
    f = fit(x,y,'a*ln(x/c)+k');
    See this question to see how to get the fitted values from f.

  7. How to change the default color/style of the fits?

    See the options fp.fitcolor, fp.fitlinestyle and fp.fitlinewidth in fitparam.

  8. What are the "initial guesses"?

    For nonlinear fits, you should provide initial guesses for the parameters of your fits to "help" the solver to converge towards the "good" values. The solver (the fminsearch function) starts from the initial guesses and then varies the coefficients in an attempt to find the best fit.
    For example, suppose you have the data
    x=1:10;
    y=[15 14.2 13.6 13.2 12.9 12.7 12.5 12.4 12.4 12.2];
    plot(x,y,'*')
    which you want to fit with an exponential decay,
    showfit('cste+a0*exp(-x/L)');
    You will obtain:

    which obvisouly is bad. By default, showfit has used cste=1, a0=1 and L=1, which is too far away from the 'true' coefficients. To specify the intial guess:
    showfit('cste+a0*exp(-x/L); cste=10');
    you now obtain:

    which is clearly much better. In this example, the initial guesses for a0 and L, which are omitted, are 1.
    You may also specify the initial guesses like this:
    showfit('cste+a0*exp(-x/L)',[10 1 1]);
    In this case, you should specify ALL the initial guesses, in the alphabetical order of the parameter names (here L, a0 and cste because L is a capital letter).

  9. What means "(lin)" or "(log)" in the equation box?

    It indicates whether the data itself, say Y, or its logarithm, LOG(Y), has been fitted. By default fit fits Y if the Y-axis of the current figure is linear, and it fits LOG(Y) if the Y-axis is logarithmic. For instance, plot a power law in log scales,
    plotsample power
    If you try
    showfit('power')
    the logarithm of the data is fitted. If you turn the Y-axis in linear scale (you may use swy for this) and fit again, you will obtain different values.
    You may also force fit to fit Y or LOG(Y) whatever the Y-axis, by specifying the optional argument
    showfit('power;log');
    showfit('power;lin');
    See the example:

    In this example, the fit with option log (upper line) "works better" when displayed with a logarithmic Y-axis.

  10. Can I extrapolate the fitted curve further than my data range?

    Yes, see the option fp.extrapol in fitparam.

  11. Where are stored the values of the fitted parameters?

    Fit your data using
    f = fit('a*x+b');
    The structure f contains all the informations about your fit. The strings 'a' and 'b' of the parameter names are stored in f.param and their values are in f.m. This works also with showfit and selectfit.
    You may also directly create in the current workspace a set of variables which contain the values of the fitted parameters:
    makevarfit(f);
    This will create two variables, 'a' and 'b'. You can also set the option 'automakevarfit = on' in fitparam: This will call makevarfit each time fit (or showfit or selectfit) is executed.

  12. Can I save a fit equation?

    Yes. First, you may define your favorite fit equation as a user-defined fit, by typing
    editfit(3,'myspectrum','E(k) = C*k^(-n);  C=0.1; n=2; log');
    This will update the file 'userfit.mat' in the EzyFit directory, so your fit equation may be re-used in a future session. You can now fit your data using this user-defined fit,
    showfit('myspectrum');
    Since a fit equation is a simple string, another way is to create a variable,
    myfit = 'E(k) = C*k^(-n);  C=0.1; n=2; log';
    and to save it in a Mat-file,
    save('myfits.mat','myfit');
    To fit your data with this fit definition, just type
    showfit(myfit);



 

2005-2006 EzyFit Toolbox