gaussian histogram so that area is equal to one.

3 次查看(过去 30 天)
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?

回答(1 个)

bym
bym 2013-4-23
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

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by