简体   繁体   中英

Matlab Histogram: connecting bin centers

just a simple question but stucked me for a while.

Is there any approaches to connect the center of each bins as curves?

eg 在此处输入图片说明

Instead of fitting it with a distribution, is there any simpler way to connect the center of each bin to form a curve?

If you are plotting data y using histogram(y) , you can use the histogram object it can return to do what you want;

h=histogram(y); hold on;
xvals = (h.BinEdges(2:end)+h.BinEdges(1:end-1))/2;
plot(xvals, h.Values, 'r');

The histogram object contains the height values (the bin counts) as well as the bin boundaries. Because there is one more bin boundary than there are bins, and because you would want to plot each point in the centre of the bin, take the average of the two nearest bin edge values (as I did in my calculation of xvals ).

To end this question, there is my final approach, which is basically the same as @Adriaan's answer.

Instead of working with index and mannual calculation, one can use the convolution method like this:

h=histgram(data); hold on;
plot(conv(h.BinEdges, [0.5,0.5],'valid'),h.BinCounts, 'Linewidth',2)
% h.BinCounts provides the data for y axies, while the previous is for x axies.

Document for the conv function can be found here .

Here is the result: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM