Relative frequency y-axis using the histfit function

15 ビュー (過去 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 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by