equal elements in historgam bins
9 次查看(过去 30 天)
显示 更早的评论
According to the help menu:
Calculate four evenly spaced quantiles.
y = quantile(x,4)
I want 10 bins with equal elements in each bin I tried :
y=quantile(x,10)
then
[counts,Id] = histc(x,y)
I received
counts=[3131
3130
3130
3130
3131
3130
3130
3130
3131
0]
and
Id=[ 0
1
2
3
4
5
6
7
8
9]
The issue is that the groups are 10 (0 to 9) but 3130 x 10 is not equal to the vector size of 34443x1. I a missing something here. as the size of each bin should be around 3443 and not 3130. Kindly, could you please spot the error and divide the histogram to 10 bins with equal elements?
1 个评论
Image Analyst
2015-8-6
34443 is not a multiple of 10 so how could all the bins have equal numbers in them?
采纳的回答
Walter Roberson
2015-8-7
nbin = 10;
y = quantile(x,nbin-1);
[counts, Id] = histc([-inf; y(:); inf]);
quantile returns N entries part way through the data. If you look at the example quantile(x,4) and notice the material about the equivalent probabilities, you can see that argument N would be for dividing into N+1 equal pieces.
histc uses the values passed as being the edges, and any value less than the first provided edge is not counted, so to count from the lowest value, prefix the quantile result with either min(x) or with -inf.
For histc, the last bin is to be used only for values that exactly equal the last edge value; the last bin is not used for all x from the last value upwards. For symmetry with the possibility of using min(x) as the first edge value, you might be tempted to use max(x) as the last edge value. However that would mean that the last bin would count only values exactly equal to max(x), so instead of max(x) use +inf as the last edge. This does theoretically lead to the possibility of an unexpected match against inf, if the input just happens to contain inf, but if that concerns you, you could easily adjust for it.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!