Uniform distribution help need.

18 次查看(过去 30 天)
southie
southie 2011-6-25
Write a MATLAB script to do the following a. Create 10000 random variables uniformly distributed between 2 and 4. b. Create a histogram to approximate the actual probability density function. c. Superimpose the actual probability density function to the above histogram.
This is what i have done but have problem with creating the density function.
n=10000; x=2*rand[1,n]+2*ones[1,n]; plot(x) xlabel('index');ylabel('Amplitude');grid pause [m,z]=hist(x); w=max(z)/10; mm=m/(10000*w); v=linspace(min(x),max(x)); y=(1/Max(x)-Min(x))*ones(size(v)); bar(z,mm) hold on plot (v,y) xlabel('randon Variable Value'); ylabel('Probability Density') hold off
  2 个评论
bym
bym 2011-6-25
please format your code using the *{}Code* button
Andrew Newell
Andrew Newell 2011-6-25
See http://www.mathworks.com/matlabcentral/answers/7885-tutorial-how-to-format-your-question.

请先登录,再进行评论。

回答(1 个)

Andrew Newell
Andrew Newell 2011-6-25
Hint: try
hist(x)

Community Treasure Hunt

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

Start Hunting!

Translated by