Skip to content

meshgrid

Generate X, Y coordinate matrices for grid evaluation.

[X, Y] = meshgrid(x, y)
[X, Y] = meshgrid(x)
[X, Y, Z] = meshgrid(x, y, z)

Returns matrices X and Y such that X(i, j) = x(j) and Y(i, j) = y(i) — the natural shape for evaluating f(X, Y) on a 2D grid. With three arguments, returns 3D coordinate arrays. With one argument, uses it for both x and y.

[X, Y] = meshgrid(-2:0.1:2);
Z = sin(X) .* cos(Y);
  • surf — 3D surface plot with colored faces.
  • contour — Contour plot of a 2D scalar field.
  • linspace — Vector of equally spaced points between two endpoints.