10.5: Plots with Error Bars

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.5: Plots with Error Bars

    Experimental data often contains uncertainty. For example, if you measure light intensity at different distances, repeated measurements may not give exactly the same value every time. A plotted point may represent an average measurement, but the actual measured values may have varied above and below that average.

    Error bars help show this variation. An error bar is usually drawn as a short vertical line passing through a data point. The length of the bar shows the amount of uncertainty, scatter, or possible measurement error associated with that point.

    Note

    Interpretation tip: Shorter error bars usually suggest less variation in the data. Longer error bars suggest more uncertainty or more spread in the measurements.

    For symmetric error bars, where the error extends the same distance above and below each point, use:

    errorbar(x, y, e)

    Here x contains the x-values, y contains the plotted y-values, and e contains the error amount for each point. The error bar at each point extends from y(i) - e(i) to y(i) + e(i).

    For asymmetric error bars, where the lower and upper errors are different, use:

    errorbar(x, y, d, u)

    In this form, d contains the lower error values and u contains the upper error values. The error bar at point i extends from y(i) - d(i) to y(i) + u(i).

    Note

    Important: The x vector, y vector, and error vector must have the same length. MATLAB needs one error value for each data point.

    Example \(\PageIndex{1}\)

    Light Intensity Data

    Suppose we measure the intensity of light at different distances from a light source. The values below represent average intensity measurements, and ydErr stores the uncertainty associated with each measurement.

    clear; clc; clf;
    
    xd = 10:2:22;
    yd = [950 640 460 340 250 180 140];
    ydErr = [30 20 18 35 20 30 10];
    
    
    errorbar(xd, yd, ydErr, 'o-')
    xlabel('Distance (cm)')
    ylabel('Intensity (lux)')
    title('Light Intensity with Error Bars')
    grid on
    
    Solution

    clipboard_eb02c72c6911665b5f311eafc7cde2d48.png

    This plot shows not only the average intensity at each distance, but also the uncertainty in each measurement. This is much more informative than plotting the average values alone.

    What Should the Error Values Represent?

    Error bars are commonly used in laboratory reports, experimental engineering, biology, chemistry, physics, and any situation where measurements have uncertainty. They help the reader judge how reliable the trend appears to be.

    The error vector can represent different things depending on the experiment. It might represent measurement uncertainty, standard deviation, standard error, tolerance, or a confidence interval. MATLAB does not decide what the error means; it only draws the bars using the values you provide.

    Note

    Reporting habit: When using error bars in a report, explain what the bars represent. For example, say whether the bars show standard deviation, standard error, or instrument uncertainty.


    This page titled 10.5: Plots with Error Bars was last modified on Tue, 30 Jun 2026 02:11:45 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.