Rewrite the script and fit a 'kernel' distribution plot into a histogram

1 view (last 30 days)
Hi,
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')

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!