How to Display Multiple Histograms in Matlab

Written by chris daniels
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Display Multiple Histograms in Matlab
(Goodshoot/Goodshoot/Getty Images)

MATLAB is a programming and data analysis environment for mathematics, engineering and science. A histogram is a type of graph representing the frequency of a certain value or a range of values in a distribution of data. MATLAB contains a built-in function for calculating and graphing histograms from data, but requires a little extra work to display two or more histograms simultaneously on the same axes.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Calculate the data for the first histogram and save it to variables for later use. Use the MATLAB function "hist" as shown:

    [counts_1, edges_1] = hist(Y,edges_in);

    Where edges_in is a vector of the beginning edges of the bins, or:

    [counts_1, edges_1] = hist(Y,nBins);

    Where nBins is the number of equally spaced bins in the histogram. If neither edges_in or nBins is given, MATLAB calculates the histogram with 10 bins.

  2. 2

    Calculate the data for the second, and any subsequent histograms.

  3. 3

    Plot the first histogram using "bar(edges_1,counts_1);"

    The appearance of the graph can be customised according to the MATLAB documentation for plotting. Alternatively, using a stairstep graph "stairs(edges_1,counts_1);" may make multiple histograms easier to see on the same graph.

  4. 4

    Type the command "hold on" into the MATLAB command window to prevent your current figure from being overwritten by the new graph.

  5. 5

    Plot the second and any subsequent histograms, customising appearance as desired.

  6. 6

    Type the command "hold off" to prevent any further drawing from being added to the figure containing your histograms.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.