How to plot probability density curve?

18 vues (au cours des 30 derniers jours)
Andi
Andi le 8 Déc 2021
Commenté : Andi le 30 Mar 2022
I have modify the strip as per my data but its the resulst are not expected. Why the movemedian=25 is fixed here.
X = readmatrix('R_0.01.csv');
r_a=[X(1,:)];
r_b=[X(2,:)];
r_c=[X(3,:)];
r_d=[X(4:8,:)];
r_e=[X(9:12,:)];
r_f=[X(13:16,:)];
r_g=[X(17:26,:)];
r_h=[X(27:48,:)];
r_i=[X(49:120,:)];
r_j=[X(121:186,:)];
r_aam = (r_a(~isnan(r_a)));
r_abm = r_b(~isnan(r_b));
r_acm = r_c(~isnan(r_c));
r_adm = r_d(~isnan(r_d));
r_aem = r_e(~isnan(r_e));
r_afm = r_f(~isnan(r_f));
r_agm = r_g(~isnan(r_g));
r_ahm = r_h(~isnan(r_h));
r_aim = r_i(~isnan(r_i));
r_ajm= r_j(~isnan(r_j));
pd = makedist('Normal')
[f1,x1,flo1,fup1] = ecdf(r_aam);
[f2,x2,flo2,fup2] = ecdf(r_abm);
[f3,x3,flo3,fup3] = ecdf(r_acm);
[f4,x4,flo4,fup4] = ecdf(r_adm);
[f5,x5,flo5,fup5] = ecdf(r_aem);
[f6,x6,flo6,fup6] = ecdf(r_afm);
[f7,x7,flo7,fup7] = ecdf(r_agm);
[f8,x8,flo8,fup8] = ecdf(r_ahm);
[f9,x9,flo9,fup9] = ecdf(r_aim);
[f10,x10,flo10,fup10] = ecdf(r_ajm);
figure
plot(x, f)
grid
title('Empirical CDF')
dfdxs1 = smoothdata(gradient(f1)./gradient(x1), 'movmedian',25);
dfdxs2 = smoothdata(gradient(f2)./gradient(x2), 'movmedian',20);
dfdxs3 = smoothdata(gradient(f3)./gradient(x3), 'movmedian',25);
dfdxs4 = smoothdata(gradient(f4)./gradient(x4), 'movmedian',25);
dfdxs5 = smoothdata(gradient(f5)./gradient(x5), 'movmedian',25);
dfdxs6 = smoothdata(gradient(f6)./gradient(x6), 'movmedian',25);
dfdxs7 = smoothdata(gradient(f7)./gradient(x7), 'movmedian',25);
dfdxs8 = smoothdata(gradient(f8)./gradient(x8), 'movmedian',25);
dfdxs9 = smoothdata(gradient(f9)./gradient(x9), 'movmedian',25);
dfdxs10 = smoothdata(gradient(f10)./gradient(x10), 'movmedian',1000);
aaa1=smooth(dfdxs1)
aaa2=smooth(dfdxs2)
aaa3=smooth(dfdxs3)
aaa4=smooth(dfdxs4)
aaa5=smooth(dfdxs5)
aaa6=smooth(dfdxs6)
aaa7=smooth(dfdxs7)
aaa8=smooth(dfdxs8)
aaa9=smooth(dfdxs9)
aaa10=smooth(dfdxs10)
figure
plot(x1, aaa1)
plot(x2, aaa2)
plot(x3, aaa3)
plot(x4, aaa4)
plot(x5, aaa5)
plot(x6, aaa6)
plot(x7, aaa7)
plot(x8, aaa8)
plot(x9, aaa9)
plot(x10, aaa10)

Réponse acceptée

Star Strider
Star Strider le 8 Déc 2021
For data with an unknown distribution, I generally use the empirical cumulative distribution (ecdf) function to get the CDF, and the use the gradient function to derive the PDF. This is generally more robust than estimating the PDF directly, at least in my experience.
.
  10 commentaires
Torsten
Torsten le 30 Mar 2022
Modifié(e) : Torsten le 30 Mar 2022
Use MATLAB's "ksdensity".
Andi
Andi le 30 Mar 2022
I try with the ksdensity but results are not expected.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by