Relative frequency y-axis using the histfit function

조회 수: 18 (최근 30일)
Robson Passos
Robson Passos 2019년 8월 7일
댓글: Robson Passos 2019년 8월 8일
Dear,
I am trying to plot two histograms with weibull probability density curves on the same figure.
However, I am having difficulty changing the y axis from absolute frequency to relative frequency.
If it was just a histogram, I could easily recalculate the y-axis values and change the yticklabel values. However I need to plot two histograms on the same figure, and the two datasets do not have the same length.
Below is a reproducible example of how I am currently doing.
data1 = wblrnd(0.4,2,[1000,1]); data1 = data1(data1 <= 1);
data2 = wblrnd(0.4,2,[900,1]); data2 = data2(data2 <= 1);
h1 = histfit(data1, 10, 'weibull')
hold on
h2 = histfit(data2, 10, 'weibull')
h1(2).Color = [.5843 .8157 .9882]
h2(2).Color = [.9100 .4100 .1700]
alpha(h1(1),.5)
alpha(h2(1),.5)
uistack(h1(2),'top')
Below is the picture I am currently generating. I want the y axis to be the relative frequency, not the absolute frequency or probability density.
teste.jpg
Could someone help me with this?
Thank you very much in advance.

채택된 답변

dpb
dpb 2019년 8월 8일
IIUC,
N1=sum(h1(1).YData);
N2=sum(h2(1).YData);
h1(1).YData=h1(1).YData/N1;
h1(2).YData=h1(2).YData/N1;
h2(1).YData=h2(1).YData/N2;
h2(2).YData=h2(2).YData/N2;
should do it...obviously, can clean it up a little...

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by