gaussian fit to 2D pcolor map
조회 수: 4 (최근 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!