フィルターのクリア

Fitting a curve to a histogram

53 ビュー (過去 30 日間)
ka chun yick
ka chun yick 2020 年 2 月 13 日
コメント済み: chi qiu 2020 年 9 月 30 日
Hi,
This is my current script. I would like to fit a curve to a histogram as shown in the picture below: What lines should i add to the existing script?
yA = randn(1000,1)*7+15;
yB = randn(1000,1)*3+7;
yC = randn(1000,1)*4+30;
% specify number of bins and edges of those bins; this example evenly spaces bins
NumBins = 25;
BinEdges = linspace(0,50,25);
% use histcounts and specify your bins
cntA = histcounts(yA,'BinEdges',BinEdges);
cntB = histcounts(yB,'BinEdges',BinEdges);
cntC = histcounts(yC,'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,[cntA',cntB',cntC'],'stacked')
  1 件のコメント
chi qiu
chi qiu 2020 年 9 月 30 日
Hey, did you find a way??

サインインしてコメントする。

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 2 月 13 日
data=[yA;yB;yC]
histfit(data)

ka chun yick
ka chun yick 2020 年 2 月 14 日
編集済み: ka chun yick 2020 年 2 月 14 日
Hi,
I added these two lines, but the plot seems not correct..... I tried
% 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
cntA = histcounts(yA,'BinEdges',BinEdges);
cntB = histcounts(yB,'BinEdges',BinEdges);
cntC = histcounts(yC,'BinEdges',BinEdges);
% plot
figure(1); cla; hold on;
data=[yA;yB;yC]
histfit(data)
% convert bin edges into bin centers
b = BinEdges(1:end-1)+diff(BinEdges)/2
% use bar
bar(b,[cntA',cntB',cntC'],'stacked')
% Labels
xlabel('Length of single walled carbon nanotubes (mm)')
ylabel('Count of CNT(log scale)')
set(gca,'YScale','log')
legend({'30(mins)', '120(mins)', '240(mins)'})
title('Count of CNT against length of SWCNTs in -0.67 degree(log scale)')

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by