Estimate pdf from a random variable
4 views (last 30 days)
Show older comments
I set up X to be the difference of two uniform random variables U1 and U2. I have constructed the histogram plot, but how would I estimate the PDF of X?
rng;
X = unifrnd(-5, 5, 1000, 1) - unifrnd(-5, 5, 1000, 1);
bincenters = (-5:0.5:5);
bins = length(bincenters);
h = zeros(bins, 1); % pre-allocating h
for i = 1:length(X)
for k = 1:bins
if X(i) > bincenters(k) - 0.5/2 && X(i) <= bincenters(k) + 0.5/2
h(k, 1) = h(k, 1) + 1;
end
end
end
pxest = h/(1000*0.5);
bar(bincenters, pxest)
0 Comments
Answers (0)
See Also
Categories
Find more on Probability Distributions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!