如何在matlab中创建高斯分布的等高线图?
答案 0 :(得分:3)
具有对称sigma且中心位于(0,0)的简单情况:
sigma = 5; % just an example value
n = 3*sigma; % cutoff point
x = -n:n;
G = 1 / (sigma * sqrt(2 * pi)) * exp(-x.^2 / (2*sigma^2)); % 1D Gaussian
G2 = G' * G; % 2D
contour(G2); % make contour plot
或者在一般情况下,中心位于任意位置,不同的sigma x和sigma y以及旋转θ:
center = [1 3]; % again, example values
sigma = [4 2];
theta = pi/3;
R = max(sigma(:))*4;
[xgrid, ygrid] = meshgrid( center(1)-R: center(1)+R,...
center(2)-R: center(2)+R);
x = (((xgrid-center(1))*cos(theta) - (ygrid-center(2))*sin(theta))/sigma(1)).^2;
y = (((xgrid-center(1))*sin(theta) - (ygrid-center(2))*cos(theta))/sigma(2)).^2;
G = exp(-(x+y)/2);
contour( xgrid, ygrid, G)
答案 1 :(得分:1)
online documentation拥有您需要的一切。查看“函数的轮廓图”部分
有示例代码,以及标记轮廓,平滑等等的各种方法。