Kernel density estimation plot with median and quartiles
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Tamir Eisenstein
il 7 Feb 2019
Risposto: Tamir Eisenstein
il 9 Feb 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 Commenti
Risposta accettata
Rik
il 8 Feb 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 Commenti
Più risposte (1)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!