Fit a distribution line in a histogram - Help!

2 次查看(过去 30 天)
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 个评论
J. Alex Lee
J. Alex Lee 2020-3-3
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 2020-3-4
Thanks. This is what i wanted. But i got a question: how to smooth the line?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by