Filter löschen
Filter löschen

Fit a distribution line in a histogram - Help!

2 Ansichten (letzte 30 Tage)
ka chun yick
ka chun yick am 3 Mär. 2020
Kommentiert: ka chun yick am 4 Mär. 2020
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 Kommentare
J. Alex Lee
J. Alex Lee am 3 Mär. 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 am 4 Mär. 2020
Thanks. This is what i wanted. But i got a question: how to smooth the line?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by