Mike Wong
Mike Wong

Reputation: 45

How to plot a probability density distribution graph in MATLAB?

I have about 10000 floating point data, and have read them into a single row matrix. Now I would like to plot them and show their distribution, would there be some simple functions to do that?

plot() actually plots value with respect to data number...which is not what I want

bar() is similar to what I want, but actually I would like to lower the sample rate and merge neighbor bars which are close enough (e.g. one bar for 0.50-0.55, and one bar for 0.55-0.60, etc) instead of having one single bar for every single data sample.

would there be a function to calculate this distribution by dividing the range into small steps, and outputting the prob density in each step?

Thank you!

Upvotes: 0

Views: 318

Answers (1)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

hist() would be best. It plots a histogram, with a lot of options which you can see by doc hist, or by checking the Matlab website. Options include a specified number of bins, or a range of bins. This will plot a histogram of 1000 normally random points, with 50 bins.

hist(randn(1000,1),50)

Upvotes: 2

Related Questions