MATLAB Answers

gaussian histogram so that area is equal to one.

14 views (last 30 days)
jenka
jenka on 23 Apr 2013
I have a quick question. I am creating my data in the following manner:
a = -100; b = 100;
x = a + (b-a) * rand(1, 500);
m = (a + b)/2;
s = 30;
DATA = gauss(x, m, s);
where the function gauss is implemented as follows:
function f = gauss(x,mu,s)
p1 = -.5 * ((x - mu)/s) .^ 2;
p2 = (s * sqrt(2*pi));
f = exp(p1) ./ p2;
Now, the area under DATA is not equal to one. So I am doing something like this to make it equal to 1:
num_bins = length(DATA);
stand_DATA = hist(DATA,num_bins) ./ sum(hist(DATA,num_bins));
Now the question is. The areaa under stand_DATA is equal to one now. But it does not make sense as num_bins = length(DATA). Isn't it in this case each bin essentially gets one and only one data point?

  0 Comments

Sign in to comment.

Answers (1)

bym
bym on 23 Apr 2013
it does not make sense to me to have the number of bins equal to your length of data. The purpose of a histogram is to describe your data in terms of intervals...not each data point. Below I have binned your data into 10 intervals and normalized the results
n = hist(data,10)
n =
4 21 53 88 135 122 52 17 6 2
sum(n/500)
ans =
1

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags