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 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