How would you normalize a histogram A
so the sum of each bin is 1
Dividing the histogram by the width of the bin, how do you draw it
I have this
dist = rand(50)
average = mean(dist, 1);
[c,x] = hist(average, 15);
normalized = c/sum(c);
bar(x, normalized, 1)
In this case, n = 50
,
- What is it the formula to get values
of mean and variance^2? We write
N(mean, (variance^2) / 50)
, but how? - How do you plot both uniform distribution and normal distribution?.
The histogram must be close to the normal distribution.
That is a very unusual way of normalizing a probability density function. I assume you want to normalize such that the area under the curve is 1. In that case, this is what you should do.
Either way, to answer your question, you can use
randn
to generate a normal distribution. You're now generating a50x50
uniform distribution matrix and summing along one dimension to approximate a normal Gaussian. This is unnecessary. To generate a normal distribution of 1000 points, userandn(1000,1)
or if you want a row vector, transpose it or flip the numbers. To generate a Gaussian distribution of meanmu
and variancesigma2
, and plot its pdf, you can do (an example)Although these can be done with dedicated functions from the statistics toolbox, this is equally straightforward, simple and requires no additional toolboxes.
EDIT
I missed the part where you wanted to know how to generate a uniform distribution.
rand
, by default gives you a random variable from a uniform distribution on[0,1]
. To get a r.v. from a uniform distribution between[a, b]
, usea+(b-a)*rand