how to mesh a grid in matlab

To mesh a grid in MATLAB, use the meshgrid function.

Here is an example:

main.m
x = linspace(-10,10,50);
y = linspace(-10,10,50);

[X,Y] = meshgrid(x,y);

Z = sin(sqrt(X.^2 + Y.^2))./(sqrt(X.^2 + Y.^2));

mesh(X,Y,Z)
xlabel('x')
ylabel('y')
zlabel('z')
173 chars
12 lines

This example creates a grid of 50 points in both x and y directions, and then generates a corresponding Z matrix using the sin function. The mesh function is then used to generate a 3D mesh plot of the data.

Note that you can adjust the arguments of linspace to change the size of the grid, and you can use any function you like to generate the Z values.

related categories

gistlibby LogSnag