MATLAB: Histogram seems to be unable to deal with histogram(​’BinEdges’​,edges,’Bi​nCounts’,c​ounts)

histogram bincounts binedgesMATLAB

Hi,
I use matlab R2015a. Within documentation : histogram('BinEdges',edges,'BinCounts',counts) manually specifies bin edges and associated bin counts. histogram plots the specified bin counts and does not do any data binning.
Nervertheless, it seems that BinCOunts isn't account for. I tried that but it doesn'T work.
histogram('BinEdges',[1:101],'BinCounts',[1:100]);
Is this my version that doesn't take it or I just miss the point ?
Thx

Best Answer

Make sure you're passing in valid edges and counts. This works perfectly fine:
img = peaks(500);
% Compute and plot histogram.
histObject = histogram(img)
% Create a new figure
figure;
% Plot (only) the histogram using the previously generated histogram object.
edges = histObject.BinEdges;
counts = histObject.Values;
histogram('BinEdges',edges,'BinCounts',counts)
Note that in this demo I took the counts from the histogram object so I know they're correct. Your bin counts is just some data you made up - it doesn't seem like it's actual histogram count data that actually came from actual real data, so of course it will look weird, but it should plot what you gave it.