How to define the bin size for a histogram

6 次查看(过去 30 天)
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
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