How to define the bin size for a histogram

3 visualizaciones (últimos 30 días)
upinderjeet
upinderjeet el 20 de Sept. de 2014
Comentada: upinderjeet el 20 de Sept. de 2014
Hello
I have 2 questions.
I am trying to create 100 bins for my histograms which covers actually 10000 data points. The command bincounts = histc(x,binranges), allows me to put the binranges value but I dont want to repeat (0 100 200..........10000)as the value for 'binranges'. So is there any shorter way to give that kind of argument for binranges to use that command. Once I know that, I can use bar(binranges,bincounts,'histc') to plot the histogram.
Second question, how do I normalize the area of the histogram to be 1.
Thanks

Respuesta aceptada

Guillaume
Guillaume el 20 de Sept. de 2014
There are two histogram functions in matlab. The other one, hist allows you to specify the number of bins instead of the edges.
As for normalising:
dist = hist(data, 100);
dist = dist / sum(dist);
  5 comentarios
upinderjeet
upinderjeet el 20 de Sept. de 2014
Thanks
upinderjeet
upinderjeet el 20 de Sept. de 2014
Hi, one more question:
I am using the following code:
X=rand(10000,1);
[N,centers] = hist(X, 100);
N = N / sum(N); figure(1)
bar(centers, N); %or plot
xlim([min(centers) max(centers)]);ylim([0 1]);
Y=pdf('uniform',X,0,1);
figure(2)
plot(Y)
I am not getting the normalized area of 1. The method you told me gives me normalized x axis of the plot but I want the total area to be 1 as well. Like, If i am able to expand the histogram plot vertically(multiply by 100), I would get area of 1. But not really sure how to achieve this. Please run my code to see my problem

Iniciar sesión para comentar.

Más respuestas (0)

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