www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/PlotMultipleHistogramsExample.m

    %% Plot Multiple Histograms
% Generate two vectors of random numbers and plot a histogram for each
% vector in the same figure. 

% Copyright 2015 The MathWorks, Inc.

x = randn(2000,1);
y = 1 + randn(5000,1);
h1 = histogram(x);
hold on
h2 = histogram(y);

%%
% Since the sample size and bin width of the histograms are different, it
% is difficult to compare them. Normalize the histograms so that all of the
% bar heights add to 1, and use a uniform bin width.
h1.Normalization = 'probability';
h1.BinWidth = 0.25;
h2.Normalization = 'probability';
h2.BinWidth = 0.25;