Fit a distribution line in a histogram - Help!

1 view (last 30 days)
Hi all,
This is my code and the result i got. Somthing is not right, i used histfit(cntH,NumBins,'kernel'), i was expecting the distribution line is starting 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 of single walled carbon nanotubes (mm)')
ylabel('Count of CNT(log scale)')
set(gca,'YScale','log')
title('Count of CNT against length of SWCNTs in 0 degree(log scale)')
  6 Comments
J. Alex Lee
J. Alex Lee on 3 Mar 2020
You need to be more specific. Presumably you want to do something with the parameters of the underlying fitted distribution.
If you just want to draw a line, you can get the bin edges and counts from the histcounts function, find the bin centers, and use the plot command on that pair.
plot(b,cntH','-')
ka chun yick
ka chun yick on 4 Mar 2020
Thanks. This is what i wanted. But i got a question: how to smooth the line?

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!