How does the hist function deal with data on the boundary between bins
Show older comments
I have been trying to create histograms using data which, by coincidence, always fall on the boundaries between created bins. Do boundary values get included in the higher or lower bin?
The resulting histogram is centred at 0 and has both positive and negative values; there is always a gap in the middle between 0 and the next positive bin. Presumably then, the function deals with positive and negative values differently, so that, for example, if your bins were -1 to 0, 0 to 1 and 1 to 2, all of the zeroes would go into the first bin and all of the ones into the third bin, leaving the middle one empty and thus producing a gap.
Is this the case and is there a way around it?
Hopefully the explanation makes sense!
Answers (1)
From the documentation (edit histc):
% N(k) will count the value X(i) if EDGES(k) <= X(i) < EDGES(k+1). The
% last bin will count any values of X that match EDGES(end). Values
% outside the values in EDGES are not counted. Use -inf and inf in
% EDGES to include all non-NaN values.
Since histc is a built-in function ( hist is based on it also), the only way to change it is to do your own implementation.
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!