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

1 visualizzazione (ultimi 30 giorni)
ka chun yick
ka chun yick il 14 Feb 2020
Commentato: ka chun yick il 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
bar(b,[cntA',cntB',cntC'],'stacked')
data=[cntA',cntB',cntC']
histfit(data,100,'kernel')

Risposte (1)

SaiDileep Kola
SaiDileep Kola il 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 Commento
ka chun yick
ka chun yick il 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?
data=[cntA',cntB',cntC']
histfit(data,100,'kernel')

Accedi per commentare.

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by