views:

333

answers:

2

I have raw observations of 500 numeric values (ranging from 1 to 25000) in a text file, I wish to make a frequency distribution in MATLAB. I did try the histogram (hist), however I would prefer a frequency distribution curve than blocks and bars.

Any help is appreciated !

+2  A: 

You could try Kernel smoothing density estimate

Francisco
+1 - You beat me to it! I just discovered this a few months ago, and use it regularly in place of histograms. Wikipedia has a fairly good explanation: http://en.wikipedia.org/wiki/Kernel_density_estimation
Doresoom
Terrific ! ..... I never knew that such levels of 'smoothing' is possible !
Arkapravo
+3  A: 

If you pass two output parameters to HIST, you will get both the x-axis and y-axis values. Then you can plot the data as you like. For instance,

[counts, bins] = hist(mydata);
plot(bins, counts); %# get a line plot of the histogram
mtrw
@mtrw : lovely one dude ! ...... you truly understood my problem !
Arkapravo
@Arkapravo - glad it worked out.
mtrw
@mtrw : Dude, it is great ..... but do you have any suggestions ....the curve look a bit jagged .... any smoothing would be the 'icing to the cake' !
Arkapravo
@Arkapravo - You can try Francisco's suggestion (http://stackoverflow.com/questions/2597743/matlab-frequency-distribution/2597831#2597831). I've never done this myself, but it appears to try and estimate the probability density, rather than just count up a histogram. You should also make sure your bins are spaced such that each has the same number of possible data. However, I suspect that if you only have 500 observations, you're not going to get a statistically meaningful measurement whatever technique you use.
mtrw
@mtrw : Francisco's method works great, however it 're-scales' the data elements, and I do not want that !
Arkapravo
Sorry @Arkapravo, I don't know anything about the kernel smoothing density estimate, and I don't have the stats toolbox. Again though, with just 500 observations I'm not sure how good any pdf estimate will be.
mtrw
@mtrw : Yeah you are right ! ..... but with more observations (say 10000) it works great !
Arkapravo
@Arkapravo you can try to do a spline of the resulting curve (histogram) or you can try to scale your Kernel curve by this factor: Max(YourSample) / Max (KernelSmoothSample). It works because it appears that kernel smoothing tries to "hit" the max value of the sample at all cost. You can change the "width" parameter to obtain "more" or "less" smoothed curves. Hope it helps
Francisco

related questions