Adjusting histogram bin width.

106 次查看(过去 30 天)
John Smith
John Smith 2015-3-17
回答: Josh Meyer 2015-3-27
I have a histogram with a large range of data. It can run up to figures of 10^135(not many), these figures however are largely irrelevant as everything interesting is happening at very close to zero(most figures are close to zero). I need to somehow fit about 20-30 bins between the range of -0.3 and 0.3 to see what is happening, but the bin widths that matlab has is too large as it just puts everything close to zero in one single bar and that's no use to me.
How do I adjust the bin widths? I tried increasing the number of bins but that doesn't seem to help, I still get one giant spike near zero and this needs to be split up to more bins.

回答(2 个)

Star Strider
Star Strider 2015-3-17
The histc function will let you define the bin edges.

Josh Meyer
Josh Meyer 2015-3-27
If you use the new histogram function, introduced in R2014b, there is a great deal of control for problems like this.
To plot a histogram with 30 bins between -0.3 and 0.3, try this:
x = randn(1000,1);
h = histogram(x,30,'BinLimits',[-0.3 0.3])
Note that when you specify the BinLimits, histogram only plots the data that falls within those limits inclusively.
To plot all of the data but still improve the resolution between -0.3 and 0.3, you can just explicitly specify all of the bin edges with a vector as the second input, perhaps something like this:
edges = [-5:0.5:-0.5, linspace(-0.5,0.5,30), 0.5:0.5:5];
h = histogram(x,edges)
More information:

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by