How to define the bin size for a histogram

조회 수: 7 (최근 30일)
upinderjeet
upinderjeet 2014년 9월 20일
댓글: upinderjeet 2014년 9월 20일
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

채택된 답변

Guillaume
Guillaume 2014년 9월 20일
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
upinderjeet
upinderjeet 2014년 9월 20일
Thanks
upinderjeet
upinderjeet 2014년 9월 20일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by