0

This is my script. I am trying to it a 'kernel' distribution plot into an existing histogram. So, how can i do that and which line should i add to the script? Or how to re-write the script? P.S. the 'yG' is the data from excel. Do i need to use the 'stacked' function in the bar(b,[cntG'], 'stacked') if i only got one group of data. I think i have made my script too complicated.....

% yG = total 
load yG
% 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
cntG = histcounts(yG,'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,[cntG'],'stacked')
% Labels   
xlabel('Length(mm)')
ylabel('Count')
Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
  • So you want to determine the probability density function (PDF) that fit your histogram ? – obchardon Mar 09 '20 at 12:25
  • Possible answer: This [answer](https://stackoverflow.com/a/56759220/8239061) (towards the end) shows how to use [`fitdist()`](https://www.mathworks.com/help/stats/fitdist.html) with the [Kernel distribution object](https://www.mathworks.com/help/stats/prob.kerneldistribution.html) and [`pdf()`](https://www.mathworks.com/help/stats/prob.normaldistribution.pdf.html) to obtain the desired plot. Is that what you're looking for? – SecretAgentMan Mar 09 '20 at 14:07
  • Related from OP: [Fit a distribution line in a histogram on Matlab](https://stackoverflow.com/q/60508853/8239061) – SecretAgentMan Mar 09 '20 at 14:09

0 Answers0