MATLAB Examples

Fit Gaussian Models Using the fit Function

This example shows how to use the fit function to fit a Gaussian model to data.

The Gaussian library model is an input argument to the fit and fittype functions. Specify the model type gauss followed by the number of terms, e.g., 'gauss1' through 'gauss8' .

Contents

Fit a Two-Term Gaussian Model

Load some data and fit a two-term Gaussian model.

[x,y] = titanium;
f = fit(x.',y.','gauss2')
plot(f,x,y)
f = 

     General model Gauss2:
     f(x) =  a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)
     Coefficients (with 95% confidence bounds):
       a1 =        1.47  (1.426, 1.515)
       b1 =       897.7  (897, 898.3)
       c1 =       27.08  (26.08, 28.08)
       a2 =      0.6994  (0.6821, 0.7167)
       b2 =       810.8  (790, 831.7)
       c2 =       592.9  (500.1, 685.7)