1
$\begingroup$

I need to plot the empirical pdf of the data:

X = [8.13010235400000,13.6713071300000,14.0362434700000,18.4349488200000,26.5650511800000,30.9637565300000,34.3803447200000,40.6012946500000,45,49.3987053500000,58.6713071300000,59.0362434700000,59.0362434700000,59.0362434700000,61.9275130600000,61.9275130600000,63.4349488200000,63.4349488200000,63.4349488200000,63.4349488200000,63.4349488200000,64.4400348300000,71.5650511800000,71.5650511800000,71.5650511800000,71.5650511800000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,75.9637565300000,77.4711922900000,77.4711922900000,77.4711922900000,77.4711922900000,77.4711922900000,77.4711922900000,77.4711922900000,77.4711922900000,77.4711922900000,78.6900675300000,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,93.1798301200000,97.1250163500000,97.7651660200000,102.528807700000,102.528807700000,102.528807700000,102.528807700000,102.528807700000,104.036243500000,104.036243500000,104.036243500000,104.036243500000,104.036243500000,104.036243500000,104.036243500000,105.255118700000,108.434948800000,108.434948800000,108.434948800000,108.434948800000,109.440034800000,116.565051200000,118.072486900000,120.963756500000,127.746805400000,130.601294600000,135,137.489552900000,139.398705400000,139.398705400000,149.036243500000,153.434948800000,159.227745300000,161.565051200000,179.999998800000,180];

I do this in Matlab as follows:

[count, bins] = hist(X, 6);
normcount     = count/sum(count);

figure, scatter(bins, normcount)
hold on;
plot(bins, normcount)

I notice the appearance of the plot changes with manual selection of bins.

My question then is: Is there any such thing as an ‘optimum’ bin size... and if there is, how do I determine it?

$\endgroup$

1 Answer 1

1
$\begingroup$

This article will give you a starting point (including MATLAB code in the Appendix) for solving your problem: https://arxiv.org/pdf/physics/0605197.pdf.

$\endgroup$
5
  • $\begingroup$ Thank you @Isabella. I would go through it asap. May i ask if you have an idea if this is the same algorithm Matlab uses for determining the default bin size? $\endgroup$
    – oma11
    Mar 25, 2018 at 15:11
  • $\begingroup$ No, this seems to be a different algorithm. You can check the results it produces against those produced by the default from Matlab. $\endgroup$ Mar 25, 2018 at 15:22
  • $\begingroup$ That's a good reference! But as it stands, this is more a comment than an answer; at least an overview of what approach the paper takes would be very helpful. $\endgroup$ Mar 25, 2018 at 16:30
  • $\begingroup$ Thank you again @ISabella. I will eventually do as you've said, but actually I thought i'd be able to have a look at the algorithm matlab uses to produce its automatic binning. I'm still searching for this... do you by chance know how i could find it? $\endgroup$
    – oma11
    Mar 25, 2018 at 17:06
  • $\begingroup$ I don't but you could contact Matlab's support to find out: mathworks.com/support/contact_us.html. $\endgroup$ Mar 25, 2018 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.