# Extract center of the bin while 3D binning

1 view (last 30 days)
Prodip Das on 6 Sep 2019
Answered: Sai Bhargav Avula on 18 Feb 2020
I have a set of xyz and corresponding "u" values for 3D binning. This is what I use to bin the variable u as shown below. Now from what I've understood, the binning takes place using bin edges. I would also like to find the center of each bin where the datapoints fall into. Ideally I want to have another variable which would store the bin-center values in the same format as the output U in this case.
xbins=min(x):binsize:max(x);
ybins=min(y):binsize:max(y);
zbins=min(z):binsize:max(z);
[~,~,cx]=histcounts(x,xbins);
[~,~,cy]=histcounts(y,ybins);
[~,~,cz]=histcounts(z,zbins); % generates indices for each direction.
U = accumarray([cx, cy, cz], u(:),[],@(vals){vals}, {});
Any help is appreciated.
Thanks!

Sai Bhargav Avula on 18 Feb 2020
Hi,
Assuming the exact center meaning the center of the dataset in the bin, the center can be estimated by finding mean of all the points in the mean(this is the centroid of the bin).
But if you mean the geometric center of the bin it is impossible to estimate to the best of my knowledge as there is not definite boundary of the boundary as the binning is done by thresholding.
Hope this helps!