meshgrid

Syntax

Description

[X,Y] =
meshgrid(x,y) returns
2-D grid coordinates based on the coordinates contained in vectors x and y. X is
a matrix where each row is a copy of x, and Y is
a matrix where each column is a copy of y. The
grid represented by the coordinates X and Y has length(y) rows
and length(x) columns.

Plot Surface

Create a 2-D grid with uniformly spaced x-coordinates and y-coordinates in the interval [-2,2].

x = -2:0.25:2;
y = x;
[X,Y] = meshgrid(x);

Evaluate and plot the function over the 2-D grid.

F = X.*exp(-X.^2-Y.^2);
surf(X,Y,F)

Starting in R2016b, it is not always necessary to create the grid before operating over it. For example, computing the expression implicitly expands the vectors x and y. For more information on implicit expansion, see Array vs. Matrix Operations.

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.