gaussian fit to 2D pcolor map
3 次查看(过去 30 天)
显示 更早的评论
I have a 2D map using pcolor function. Now I want to fit gaussian to this 2D map P1. How can I do that?
%[xx,yy] = meshgrid(x,y);
xx = [ 3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323
3.9202 7.6226 11.3250 15.0274 18.7298 22.4323];% 8x6 matrix
yy = [ 5.0820 5.0820 5.0820 5.0820 5.0820 5.0820
6.6220 6.6220 6.6220 6.6220 6.6220 6.6220
8.1620 8.1620 8.1620 8.1620 8.1620 8.1620
9.7020 9.7020 9.7020 9.7020 9.7020 9.7020
11.2420 11.2420 11.2420 11.2420 11.2420 11.2420
12.7820 12.7820 12.7820 12.7820 12.7820 12.7820
14.3220 14.3220 14.3220 14.3220 14.3220 14.3220
15.8620 15.8620 15.8620 15.8620 15.8620 15.8620];% 8x6 matrix
C = [ 0 30 133 199 143 27 0 NaN
123 614 765 832 810 590 100 NaN
388 787 897 891 903 857 442 NaN
125 570 744 737 782 659 176 NaN
0 53 180 270 210 63 0 NaN
NaN NaN NaN NaN NaN NaN NaN NaN] ;% C is a 6x8 matrix of data
P1 = pcolor(xx',yy',C);
0 个评论
回答(1 个)
Matt J
2022-8-19
编辑:Matt J
2022-8-19
You could try gaussfitn,
idx=~isnan(C);
xy=[xx(idx),yy(idx)];
params=gaussfitn(xy,C(idx));
[D,A,mu,sigma]=deal(params{:})
D =
190.8900
A =
835.3517
mu =
11.3936
11.1766
sigma =
151.2489 -130.1645
-130.1645 114.3164
8 个评论
Matt J
2022-8-27
编辑:Matt J
2022-8-27
Perhaps as follows.
idx = ~isnan(C);
xy = [xx(idx),yy(idx)];
params = gaussfitn(xy,C(idx));
[D,A,mu,sigma] = deal(params{:});
% asuume mu=0,bucause mu from param is 2x1 matrix and the dim is
% not agree for z calculation:
[X,Y]=meshgrid(mu(1)+linspace(-3,3)*sqrt(sigma(1)),...
mu(2)+linspace(-3,3)*sqrt(sigma(end)),...);
dXY=[X(:),Y(:)]-mu(:)';
Z = D + A*exp( -0.5 *sum((sigma\dXY).*dXY.',1) );
Z=reshape(Z,size(X));
surf(X,Y,Z); hold on;
scatter(xy(:,1),xy(:,2)); hold off
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!