Kernel density estimation plot with median and quartiles
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tamir Eisenstein
le 7 Fév 2019
Réponse apportée : Tamir Eisenstein
le 9 Fév 2019
Hi,
I used this to generate a kernel density estimation plot:
[f,xi] = ksdensity(myvector);
figure
plot(xi,f);
How can I insert three vertical lines in the plot representing the median and 1st & 3rd quartiles?
Thanks,
Tamir
0 commentaires
Réponse acceptée
Rik
le 8 Fév 2019
I don't have the statistics toolbox, so I needed to generate some random data myself, but the code below should do what you need.
%generate f,xi data
gauss_fun=@(x,mu,sd) 1/sqrt(2*pi*sd^2)*exp(-(x-mu).^2/(2*sd^2));
xi=linspace(-8,8,500);
f=gauss_fun(xi,0,2);
%plot original plot
figure(1),clf(1)
plot(xi,f)
y=cumsum(f);y=y/y(end);
Q1=find(y>0.25,1);
Q2=find(y>0.5 ,1);
Q3=find(y>0.75,1);
%plot the 3 lines
hold on
plot(xi(Q1)*[1 1],[0 f(Q1)],'r')
plot(xi(Q2)*[1 1],[0 f(Q2)],'r')
plot(xi(Q3)*[1 1],[0 f(Q3)],'r')
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Regression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!