How Can I Add Gaussian Curve Fit To another Gaussian Curve Obtained From An Image Profile??

Dear All! I have used the improfile function to obtain a gaussian profile from an image. How can I use the FMINSEARCH function to add a gaussian fit to it?? I have attached the profile here and below is the matlab code I am working with. Please,help!!
%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function [estimates, model] = fitcurvedemo(p, ydata)
p = (-3:0.1:3)';
ydata = 20*exp ( - ((p-0).^2) / (2*0.3.^2))%+ randn(size(p));
% Call fminsearch with a random starting point.
start_point = rand(1, 2,3);
model = @gauss;
estimates = fminsearch(model, start_point);
% expfun accepts curve parameters as inputs, and outputs sse,
% the sum of squares error for A*exp(-lambda*xdata)-ydata,
% and the FittedCurve. FMINSEARCH only needs sse, but we want
% to plot the FittedCurve at the end.
function [sse, FittedCurve] = gauss(params)
h = params(1);
po = params(2);
w = params(3);
FittedCurve = h*exp ( - ((p - po).^2) / (2*w.^2));;
ErrorVector = FittedCurve - ydata;
sse = sum(ErrorVector .^ 2)
end
plot(p, ydata, '*')
hold on
[sse, FittedCurve] = model(estimates);
plot(p, FittedCurve, 'r')
xlabel('p [position]')
ylabel('f(estimates,xdata)')
title('Fitting to function ');
legend('data')
hold off
end

Answers (0)

Categories

Asked:

on 5 Dec 2013

Edited:

on 5 Dec 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!