The code generated the plot in the following way:
- The loads function is used to load the data (x, y and error) from the file 'arraydat.dat' into the spec1d object s.
- The spectrum in s is then fitted to a Gaussian lineshape using the fits function. As no initial parameter values were given, the fitting routine estimates them from a moment analysis using the function peakm. The parameters of the fit are returned in the structure fitdata, and the fitted values and original data in sfit.
- plot is used to plot the data and fit.
- Finally, the fit parameters in fitdata are added to the plot using formatpars.
In this example, each command was typed at the matlab prompt. They can of course be placed in a file, which is then run from the commad line. This allows the steps used in a complex data analysis to be stored for editing, and also as a record of what was done.
Both loads and fits are much more flexible than this example suggests, as will be made clear in the other examples. Check the
help supplied with each function for details.