Make a curve and fit it in a "stacked" histogram

1 回表示 (過去 30 日間)
ka chun yick
ka chun yick 2020 年 2 月 14 日
コメント済み: ka chun yick 2020 年 2 月 19 日
I tried to make a curve in a "stacked" histogram, In line 23 & 24, i added "data=[cntA' ,cntB' ,cntC'] & histfit(data,100,'kernel'). But this is a "stacked" histogram and everthing get crahed. Can you check for my code please?
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')
data=[cntA',cntB',cntC']
histfit(data,100,'kernel')

回答 (1 件)

SaiDileep Kola
SaiDileep Kola 2020 年 2 月 17 日
From your code I see that, “data is a matrix which is input to histfit function, but histfit expects a vector input , thereby you can accordingly give input to get what you need.
For further information you can refer to the documentation page.
  1 件のコメント
ka chun yick
ka chun yick 2020 年 2 月 19 日
I read the documentation and tried it again, i still got some error. Could you tell me that what need to be added in the code?
data=[cntA',cntB',cntC']
histfit(data,100,'kernel')

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by