convert a range vector of bin centers to bin edges. Bin Centers and edges are non-uniform
19 views (last 30 days)
Show older comments
Is there a trivial way of converting a vector that contain bin centers to bin edges. The caveat here is that they are unequal. Does matlab provide a trivial way to do it?
Thanks
1 Comment
Answers (3)
Image Analyst
on 22 Oct 2013
Where do you want the edges? Exactly half-way between the centers? If so you simply use conv():
% Make up some non-uniformly spaced bin centers.
binCenters = unique(sort(randi(99, 1,10)))
% Get edges half way in between.
binEdges = conv(binCenters, [0.5, 0.5], 'valid')
% Define end points outside of bin centers.
binEdges = [0 binEdges inf]
0 Comments
W. Owen Brimijoin
on 22 Oct 2013
If we assume the simplest case, that the edges should be precisely between the centres (i.e., not geometric, or logarithmic, etc), and that the first and last edge should be -inf and +inf, respectively, then this is a simple solution:
%example of random bin centres:
centers = cumsum(randi(10,20,1))
%create equidistant edges:
edges = [-inf;centers(:)+[diff(centers(:))/2;inf]];
0 Comments
tsan toso
on 23 Oct 2013
3 Comments
Image Analyst
on 23 Oct 2013
I agree with Owen. The formula make the edges exactly half way between the original centers, but the distance from the new edges to the original centers will be different on each side of the original center, unless you have uniformly spaced centers.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!