简体   繁体   English

Matlab直方图:连接垃圾箱中心

[英]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; 如果要使用histogram(y)绘制数据y ,则可以使用它可以返回的histogram对象来执行您想要的操作;

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 ). 因为箱的边界比箱的边界多,并且由于您想在箱的中心绘制每个点,所以取两个最近的箱边缘值的平均值(就像我在xvals计算中xvals )。

To end this question, there is my final approach, which is basically the same as @Adriaan's answer. 为了结束这个问题,我有最后一种方法,基本上与@Adriaan的答案相同。

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 . 可以在此处找到有关conv函数的文档。

Here is the result: 结果如下: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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