MATLAB Answers

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

10 views (last 30 days)
ka chun yick
ka chun yick on 14 Feb 2020
Commented: ka chun yick on 19 Feb 2020
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


Sign in to comment.

Answers (1)

SaiDileep Kola
SaiDileep Kola on 17 Feb 2020
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 Comment

ka chun yick
ka chun yick on 19 Feb 2020
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?

Sign in to comment.


Translated by