function [Z] = gauss2d(x, y, mu, sigma) %GAUSS2D Returns the two dimensional gaussian with the given properties. % % Usage: gauss2d(x,y,mu,sigma) % where % x : 1-d array of x values % y : 1-d array of y values % mu : [mu_x, mu_y] % sigma : [sigma_x_squared, sigma_xy; sigma_yx; sigma_y_squared] [X, Y] = meshgrid(x-mu(1), y-mu(2)); coef = 1/(2 * pi * sqrt(det(sigma))); isig = inv(sigma); Z = coef * exp(-0.5 * (X.*(X.*isig(1,1)+Y.*isig(1,2)) + (Y.*(X.*isig(2,1) + Y.*isig(2,2))))); % % Author: % Bill Baxter % Comp 235 % October 13, 1995