Borrar filtros
Borrar filtros

Adjusting histogram bin width.

61 visualizaciones (últimos 30 días)
John Smith
John Smith el 17 de Mzo. de 2015
Respondida: Josh Meyer el 27 de Mzo. de 2015
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.

Respuestas (2)

Star Strider
Star Strider el 17 de Mzo. de 2015
The histc function will let you define the bin edges.

Josh Meyer
Josh Meyer el 27 de Mzo. de 2015
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:

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by