Reputation: 71
histcounts(1:100,'BinWidth',50)
returns
49 51
Why doesn't it return
50 50
instead?
Upvotes: 1
Views: 969
Reputation: 1283
Histogramming 1 to 100 inclusive with h = histogram(1:100, 'BinWidth', 50)
gives:
Let's see the bin edges:
h.BinEdges
ans =
0 50 100
From MATLAB's help:
Each bin includes the left edge, but does not include the right edge, except for the last bin which includes both edges
That means that values 1 to 100 are histogrammed in this format:
Bin 1 => edges: [0 50) => Included values: [1, 2, 3, .., 49] (n = 49)
Bin 2 => edges: [50 100] => Included values: [50, 51, 52, .., 100] (n = 51)
histcount(X)
partitions X
in the same manner as histogram(X)
. Therefore, the results are what you should expect and in fact very reasonable.
Upvotes: 1