10.13: Mesh and Surface Plots

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    10.13: Mesh and Surface Plots

    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.

    Example \(\PageIndex{1}\)

    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

    clipboard_e8a2377de5e3e1298b2f071102de54662.png

    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.

    Note

    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.