matlab的fit只有一维高斯的拟合类型'gauss1','gauss2'等等,想要拟合简单的二维正态分布只能自己写拟合类型
x = conv(-20:0.1:20,[1 1],'valid')/2;
y = x;
[x,y] = meshgrid(x,y);
x = reshape(x,[],1);
y = reshape(y,[],1);
d = reshape(d,[],1);
gauss2d = fittype('a*exp(-1/2*(((x-b1)/c)^2+((y-b2)/c)^2))',...
'dependent',{'z'},'independent',{'x','y'},'coefficients',{'a','b1','b2','c'});
f = fit([x,y],d,gauss2d);
如果只想得到标准差,也可以将原数据d压缩为一维,再进行gauss1的拟合
x = conv(-20:0.1:20,[1 1],'valid')/2;
d = sum(d,1);
x = reshape(x,[],1);
d = reshape(d,[],1);
f = fit(x,d,'gauss1');
sigma = f.c/sqrt(2);
需要注意的是gauss1的函数是'a*exp(-((x-b)/c)^2)',因此标准差应该是c/sqrt(2)。