Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
ka chun yick
ka chun yick le 14 Fév 2020
Commenté : ka chun yick le 19 Fév 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')

Réponses (1)

SaiDileep Kola
SaiDileep Kola le 17 Fév 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 commentaire
ka chun yick
ka chun yick le 19 Fév 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')

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by