Introducing uncertainty to histogram bins

5 views (last 30 days)
Darui Li
Darui Li on 1 May 2015
Answered: Guillaume on 1 May 2015
Hi everyone,
I'm currently constructing a graph where some y values are binned to specific intervals of x-values. My issue here is that due to experimental limitations the bin-edges I define should have a fixed integer value uncertainty (e.g. +- 25) so that the y values that fall into these uncertainties are also counted. The codes I'm using for defining the bins are as the following:
Interval = 1000000;
NumberOfPoints = max(x)/Interval;
binEdge = linspace(min(x),max(x),NumberOfPoints);
[N,Edges] = histc(x,binEdge);
Intensity = accumarray(Edges,y');
So the question is how can I modify this in such a way to introduce the uncertainties to the edges of the bins?
Your help is greatly appreciated
  2 Comments
Guillaume
Guillaume on 1 May 2015
So to clarify, you want a value within ± 25 of a bin edge to be counted in both bins, or something else?

Sign in to comment.

Answers (1)

Guillaume
Guillaume on 1 May 2015
Assuming that the spacing between your bins is greater than your uncertainty, I would simply create additional bins around each edge:
binEdge = 0:100:1000; %for example
uncertainty = 25; %for example
assert(all(diff(binEdge) > uncertainty), 'bins won''t be monotinically increasing')
newbinEdges = [binEdge - uncertainty; binEdge; binEdge + uncertainty];
newbinEdges = newbinEdges(:)
[~, idx] = histc(x, newbinEdges); %note that the 2nd return value of histc are not edges but indices
Intensity = accumarray(idx, y');
%Now add the uncertainty bins to central bins:
%The central bins (original bins) are at indices 2:3:end
%Indices 1:3:end are values within -uncertainty of the bin edges
%Indices 3:3:end are values within +uncertainty of the bin edges
Intensity = Intensity(2:3:end) + Intensity(1:3:end) + Intensity(3:3:end)

Categories

Find more on Data Distribution Plots 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!