问题
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