Build a Gaussian grid with Matlab

In the following code, I can draw a graph of one two-dimensional Gaussian function:

x=linspace(-3,3,1000); y=x'; [X,Y]=meshgrid(x,y); z=exp(-(X.^2+Y.^2)/2); surf(x,y,z);shading interp 

This is a plot created:

enter image description here

However, I would like to build a grid with the specified number x of these 2D Gaussians. Think of the following picture in the form of the above plot, which I would like to create (where, in particular, the grid is made of 5x5 2D Gaussian). Each Gaussian weight must be weighted by such a factor that if it is negative, then Gaussian indicates negative values โ€‹โ€‹of the z axis (black dots in the grid below), and if it is positive, as in the above image (white dots in the grid below).

enter image description here

Let me give you some mathematical details. The grid corresponds to a mixture of 2D Gaussians, summed up as in the following equation:

enter image description here

In which each Gaussian has its own mean and deviation.

Note that each Gaussian mixture must be placed in a specific (X, Y) coordinate so that they are equally distant from each other. for example, think of central Gaussian in (0,0), then others should be in (-1,1) (0,1) (1,1) (-1,0) (1,0) (-1, - 1) (0, -1) (1, -1) in the case of a grid with a dimension of 3x3.

Can you provide me (and explain to me) how I can make such a plot? Thank you in advance.

+6
source share
1 answer

In fact, you said yourself, put it (as an example for funds only)

 [X,Y]=meshgrid(x,y); % //mesh g_centers = -3:3; [x_g,y_g] = meshgrid(g_centers,g_centers); % //grid of centers (coarser) mu = [x_g(:) , y_g(:)]; % // mesh of centers in column z = zeros(size(X)); for i = 1:size(mu,1) z= z + exp(-((X-mu(i,1)).^2+(Y-mu(i,2)).^2)/( 2* .001) ); end surf(X,Y,z);shading interp 

enter image description here

+5
source

All Articles