Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help overlaying a Normal (Gaussian) Curve

Subject: Help overlaying a Normal (Gaussian) Curve

From: Mark Alesandro

Date: 21 Nov, 2002 19:43:24

Message: 1 of 2

I'm doing some work with data that is distributed exponentially, and
I'd like to show that the Central Limit Theory holds for only small
groups of data. My only difficulty at this point is figuring out how
to overlay a Normal (Gaussian) curve overtop of my existing histogram
to show that it does in fact tend to be normal.

I'm taking my exponential data, 1000 sums of 10 numbers, and
normalizing it with the normalize function.

From there I'm plotting it, with hist(x,250) and getting my somewhat
normal distribution from -1 to 1.

What I'd like to do is overlay the actual normal Gaussian curve to
show how it is approaching it. Maybe this is more of a question of
the math then of Matlab, but I'm wondering if there is a function in
the statistics toolbox that will help me with this?

Any tips would be greatly appreciated.

Subject: Help overlaying a Normal (Gaussian) Curve

From: Peter Perkins

Date: 22 Nov, 2002 09:30:52

Message: 2 of 2

> What I'd like to do is overlay the actual normal Gaussian curve to
> show how it is approaching it. Maybe this is more of a question of
> the math then of Matlab, but I'm wondering if there is a function in
> the statistics toolbox that will help me with this?

There is: NORMPDF gives you the density of a normal distribution, you just have
to scale it properly so that it integrates to the same thing as the histogram's
envelope. The function below does this. Hope it helps.

You might find that QQPLOT is a better way of doing what you want. It's
sometimes hard to judge how "normal" a histogram is, and a qqplot gives you a
much easier way to see skewness and kurtosis relative to the normal -- just look
at the ends of the plot.

- Peter Perkins
   The MathWorks, Inc.


function parmhat = normplot(x, params)
%NORMPLOT Plot fitted against observed for normally distributed data.
% NORMPLOT(X) fits a normal distribution to X, and plots the fitted pdf
% overlayed on a histogram of X.
%
% NORMPLOT(X, PARAMS) plots the pdf based on the values in PARAMS.
%
% See also NORMFIT, NORMLIKE, NORMPDF.

if nargin < 2
     [mu,sigma] = normfit(x);
else
     mu = params(1); sigma = params(2);
end
parmhat = [mu, sigma];

xmin = min(x); xmax = max(x); xrange = range(x);
binw = xrange / 50;
edges = xmin + binw*(0:50);
n = histc(x, edges);
bar(edges, n, 'histc', 'w');
hold on
xx = xmin:(xrange/1000):xmax;
plot(xx, binw*length(x)*normpdf(xx,mu,sigma), 'b');
title('Normal Fit');
legend('Fitted PDF', 'Observed Data');
hold off

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us