MATLAB: How to get the average value in the histogram bins

binshistogram

I have a large data set of sample points plotted, 2500×2500, and I put these into a histogram using histogram(dist,'BinWidth',60). How can I get the average values of the data in these bins? Or how can I get the values that are in these bins so I can get the average value in each bin?

Best Answer

Try this:
dist = 2000 * rand(2500, 2500);
hObj = histogram(dist,'BinWidth',60)
grid on;
yticks([0:5000:200000]);
% Compute the mean value of the original data.
meanDataValue = mean(dist(:))
% Compute the mean number of counts in each bin.
meanBinCounts = mean(hObj.Values)