Hi John, if you type "help hist", you'll find information about specifying the bar centers. This implicitly controls the width of the bins that the bars cover.
If you want to change the gap between the bars, see "help hist" for information about returning the bar heights instead of plotting them, and "help bar" for information about drawing bars and controlling the space between them.
For example:
X = randn(1e3,1);
N = hist(X,22);
bar(N,1);
As far as whether the histogram is appropriate or how to "normalize" it. Can you be more specific? People generally plot a histogram in two ways:
1.) the raw frequency or count histogram 2.) a probability histogram (as you have almost done), so that they can overlay a PDF for comparison.
Here's an example of that (requires Statistics Toolbox):
Data = randn(1000,1);
binWidth = 0.7;
binCtrs = -3:0.7:3;
n=length(Data);
counts = hist(Data,binCtrs);
prob = counts / (n * binWidth);
H = bar(binCtrs,prob,'hist');
set(H,'facecolor',[0.5 0.5 0.5]);
hold on;
x = -3:.1:3;
y = normpdf(x,0,1);
plot(x,y,'k','linewidth',2);
Best Answer