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
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.
Calculate the data for the second, and any subsequent histograms.
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.
Type the command "hold on" into the MATLAB command window to prevent your current figure from being overwritten by the new graph.
Plot the second and any subsequent histograms, customising appearance as desired.
Type the command "hold off" to prevent any further drawing from being added to the figure containing your histograms.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for