[英]Matlab Histogram: connecting bin centers
如果要使用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');
直方圖對象包含高度值(箱計數)以及箱邊界。 因為箱的邊界比箱的邊界多,並且由於您想在箱的中心繪制每個點,所以取兩個最近的箱邊緣值的平均值(就像我在xvals
計算中xvals
)。
為了結束這個問題,我有最后一種方法,基本上與@Adriaan的答案相同。
除了使用索引和人工計算之外,還可以使用如下的卷積方法:
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.
可以在此處找到有關conv
函數的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.