10.16: Common Mistakes and Best Practices

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.16: Common Mistakes and Best Practices

    Problem

    Likely cause

    How to fix it

    MATLAB gives an error about vector lengths.

    x and y do not have the same number of elements.

    Check length(x) and length(y).

    A new plot replaces the old plot.

    hold on was not used.

    Use hold on before adding another curve.

    Plot looks messed up. A figure with an existing plot was already open. Use clf to clean up the exisitng plots.

    Legend labels do not match the curves.

    Legend labels are not in the same order as plots.

    List legend entries in the order the curves were plotted.

    Plot has no context.

    Missing title or axis labels.

    Add title, xlabel, and ylabel.

    3D mesh looks blocky.

    Too few x and y data points.

    Use more points in the x and y vectors.

    Subplot appears in the wrong place.

    Incorrect subplot position n.

    Remember that subplot positions are counted row by row.

    Bars overlap.

    Bar width is too large.

    Use a smaller width value.


    This page titled 10.16: Common Mistakes and Best Practices 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.