Relative frequency y-axis using the histfit function

9 visualizaciones (últimos 30 días)
Robson Passos
Robson Passos el 7 de Ag. de 2019
Comentada: Robson Passos el 8 de Ag. de 2019
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.

Respuesta aceptada

dpb
dpb el 8 de Ag. de 2019
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...

Más respuestas (0)

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by