% Using a preliminary fit with a simpler peak shape to obtain a first-guess
% start value to be used for a subsequent fit with a more complex shape.
load DataMatrix3 
NumTrials=1;
% Preliminary fit with a 3-peak Gaussian model (shape=1)
figure(1)
[FitResults,GOF]=peakfit(DataMatrix3,2420,440,3,NumTrials,31,1);
subplot(2,1,1);
title(' Preliminary fit with a 3-peak Gaussian model (shape=1)')

figure(2)
% Fitting the same data with three exponentially-broadened Gaussians
% (shape=5), using the previous simple fit as the basis of the "first
% guess" vector for this fit. This fit yields a much lower fit error and
% the residuls are a little more random and less wavy:
disp('Calculating........')
R=FitResults; % R=Previous fit results, used in the next line
firstguess=[R(1,2) R(1,4) R(2,2) R(2,4) R(3,2) R(3,4)]; % Construct first guess
[FitResults,GOF]=peakfit(DataMatrix3,2420,440,3,5,30,NumTrials,firstguess);
subplot(2,1,1);
title('Same data with three exponentially-broadened Gaussians (shape 5)')

figure(3)
% Same data fit with three exponentially-broadened variable-tau Gaussians
% (shape=31), using the same "first guess" vector that has been expanded
% with the addition of initial tau values.
tau=30;
firstguess2=[R(1,2) R(1,4) tau R(2,2) R(2,4) tau R(3,2) R(3,4) tau]; % Construct first guess
[FitResults,GOF]=peakfit(DataMatrix3,2420,440,3,5,31,NumTrials,firstguess);
subplot(2,1,1);
title('Same data, but with variable tau value determined by the fit (shape 31).')