close all
clear all
clc
x=-50:0.1:50
[m,n]=size(x);
a=1;
b=4;
c=10;
y=zeros(m,n);
for i=1:n
y(i)=a*exp(-(x(i)-b).^2/c.^2)+0.1*rand(1);
end
figure(1)
plot(x,y,'r.');
[x, y] = prepareCurveData( x, y);
ft = fittype( 'gauss1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
[fitresult, gof] = fit( x, y, ft, opts );
a=fitresult.a1;
b=fitresult.b1;
c=fitresult.c1;
y1=a*exp(-(x-b).^2/c.^2);
figure(1)
plot(x,y,'r')
hold on
plot(x,y1,'b')