Opening the book…
A function of two independent variables can be visualized using a 3D mesh plot or surface plot. For example, consider the function:
Z = X^2 + Y^2
To plot this function, MATLAB needs all combinations of x and y values. The meshgrid function helps us create those combinations.
Creating mesh and surface plots
clear; clc; clf;
x = 1:3;
y = 1:5;
[X, Y] = meshgrid(x, y);
Z = X.^2 + Y.^2;
subplot(1,2,1)
mesh(X, Y, Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Mesh Plot of Z = X^2 + Y^2')
subplot(1,2,2)
surf(X, Y, Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Surface Plot of Z = X^2 + Y^2')
Solution

The matrix X contains copies of the x vector across rows, and the matrix Y contains copies of the y vector down columns. Together, X and Y describe a grid of points. The matrix Z gives the height of the surface at each point.
Plot smoothness: If the x and y vectors contain only a few points, the mesh or surface may look rough. Using more points usually creates a smoother-looking plot.
This page titled 10.13: Mesh and Surface Plots was last modified on Tue, 30 Jun 2026 02:11:47 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.