Fit a distribution line in a histogram on Matlab

随声附和 提交于 2021-01-29 06:32:34

问题


This is my code and the result I got. Something is not right — I used histfit(cntH,NumBins,'kernel'), and I was expecting the distribution line to start from zero and fit into the bars

How can I fix that?

clear all
clc
% yG = total 
load yH

% specify number of bins and edges of those bins; this example evenly spaces bins
NumBins = 100;
BinEdges = linspace(0,35,70);
% use histcounts and specify your bins
cntH = histcounts(yH,'BinEdges',BinEdges);

% plot
figure(1); cla; hold on;
% convert bin edges into bin centers
b = BinEdges(1:end-1)+diff(BinEdges)/2
% use bar
bar(b,[cntH'],'stacked')
histfit(cntH,NumBins,'kernel');
% Labels   
xlabel('Length (mm)')
ylabel('Count (log scale)')
set(gca,'YScale','log')
title('Count (log scale)')

来源:https://stackoverflow.com/questions/60508853/fit-a-distribution-line-in-a-histogram-on-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!