Plot of a fitted normal distribution

12 vues (au cours des 30 derniers jours)
Leo
Leo le 24 Mar 2021
Commenté : Adam Danz le 27 Mar 2021
Hello!
I have following problem:
My data consists of a vector x, which contains the possible results of a property (e.g. x = particle size), and a vector y, which contains the relative frequency of x.
For example:
x = 0,1 ; 0,5 ; 1 ; 5 ; 10 ; 50 ; 100; 500
y = 7% ; 9% ; 12% ; 15% ; 30% ; 13% ; 8% ; 6%
I don´t have any absolute frequencies.
I want to plot a fitted normal distribution of this data.
Thank You!
Best regards
Leo
  2 commentaires
Adam Danz
Adam Danz le 24 Mar 2021
Could you replace the x and y lines with something we can copy-paste into matlab without errors?
Leo
Leo le 24 Mar 2021
Sorry, my mistake. FYI: I write the relative frequencies without the percent sign.
x
0.1000 0.5000 1.0000 5.0000 10.0000 50.0000 100.0000 500.0000
y
0.0700 0.0900 0.1200 0.1500 0.3000 0.1300 0.0800 0.0600

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 25 Mar 2021
Modifié(e) : Adam Danz le 25 Mar 2021
x = [0.011 0.013 0.015 0.017 0.02 0.023 0.026 0.03 0.034 0.039 0.044 0.051 0.058 0.067 0.076 0.087 0.1 0.115, ...
0.131 0.15 0.172 0.197 0.226 0.259 0.296 0.339 0.389 0.445 0.51 0.584 0.669 0.766 0.877 1.005 1.151 1.318, ...
1.51 1.729 1.981 2.269 2.599 2.976 3.409 3.905 4.472 5.122 5.867 6.72 7.697 8.816 10.097 11.565 13.246, ...
15.172 17.377 19.904 22.797 26.111 29.907 34.255 39.234 44.938 51.471 58.953 67.523 77.34 88.583 101.46, ...
116.21 133.103 152.453 174.616 200 229.075 262.376 300.518 344.206 394.244 451.556 517.2 592.387 678.504, ...
777.141 890.116 1019.515 1167.725 1337.481 1531.914 1754.613 2009.687 2301.841 2636.467 3000];
y = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.00036 0.0012533, ...
0.00147 0.00151 0.0013867 0.0011333 0 0 0 0 0 0 0 0 0.00084 0.0025433 0.0058567 0.012833 0.025703 0.048463, ...
0.079867 0.10807 0.11754 0.12896 0.13169 0.11523 0.086417 0.056513 0.03343 0.01883 0.010793 0.0059967, ...
0.0033333 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
f = fit(log(x(:)),y(:),'gauss1');
x0 = linspace(min(log(x)), max(log(x)), 100);
y0 = feval(f,x0);
clf()
hold on
plot(log(x),y,'b-','LineWidth', 3, 'DisplayName', 'Data')
plot(x0,y0, 'r--', 'LineWidth', 3, 'DisplayName', 'fit')
xlabel('log(x)')
ylabel('y')
title([formula(f), newline(), strjoin(compose('%s=%.3f ',string(coeffnames(f)), coeffvalues(f)'))], ...
'FontName','FixedWidth')
legend()
grid on
box on
  8 commentaires
Leo
Leo le 27 Mar 2021
Ok, thank you!
Best regards! :)
Adam Danz
Adam Danz le 27 Mar 2021
Glad I could help.

Connectez-vous pour commenter.

Plus de réponses (1)

David Hill
David Hill le 24 Mar 2021
x=[ 0.1000 0.5000 1.0000 5.0000 10.0000 50.0000 100.0000 500.0000];
y=[0.0700 0.0900 0.1200 0.1500 0.3000 0.1300 0.0800 0.0600];
z=[];
y=floor(100*y);
x=log10(x);%looks like your data is logarithmic (if you don't take log(x), normal distribution will not be great)
for k=1:length(x)
z=[z,repmat(x(k),1,y(k))];%replicate the data based on the frequencies
end
pd=fitdist(z','Normal');
X=-3:.1:5;
Z = normpdf(X,pd.mu,pd.sigma);
plot(X,Z);
  3 commentaires
Adam Danz
Adam Danz le 25 Mar 2021
We can't access data the way you've shared it.
One option is to use formatted code to supply data in a copy-paste format such as
x = [ 1 2 3
4 5 6
7 8 9];
Another option is to save the data to a mat file and attach the file.
Leo
Leo le 25 Mar 2021
x = 1000*[0.000011000000000 0.000013000000000 0.000015000000000 0.000017000000000 0.000020000000000 0.000023000000000 0.000026000000000 0.000030000000000 0.000034000000000 0.000039000000000 0.000044000000000 0.000051000000000 0.000058000000000 0.000067000000000 0.000076000000000 0.000087000000000 0.000100000000000 0.000115000000000 0.000131000000000 0.000150000000000 0.000172000000000 0.000197000000000 0.000226000000000 0.000259000000000 0.000296000000000 0.000339000000000 0.000389000000000 0.000445000000000 0.000510000000000 0.000584000000000 0.000669000000000 0.000766000000000 0.000877000000000 0.001005000000000 0.001151000000000 0.001318000000000 0.001510000000000 0.001729000000000 0.001981000000000 0.002269000000000 0.002599000000000 0.002976000000000 0.003409000000000 0.003905000000000 0.004472000000000 0.005122000000000 0.005867000000000 0.006720000000000 0.007697000000000 0.008816000000000 0.010097000000000 0.011565000000000 0.013246000000000 0.015172000000000 0.017377000000000 0.019904000000000 0.022797000000000 0.026111000000000 0.029907000000000 0.034255000000000 0.039234000000000 0.044938000000000 0.051471000000000 0.058953000000000 0.067523000000000 0.077340000000000 0.088583000000000 0.101460000000000 0.116210000000000 0.133103000000000 0.152453000000000 0.174616000000000 0.200000000000000 0.229075000000000 0.262376000000000 0.300518000000000 0.344206000000000 0.394244000000000 0.451556000000000 0.517200000000000 0.592387000000000 0.678504000000000 0.777141000000000 0.890116000000000 1.019515000000000 1.167725000000000 1.337481000000000 1.531914000000000 1.754613000000000 2.009687000000000 2.301841000000000 2.636467000000000 3.000000000000000]
y = [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.000360000000000 0.001253333333333 0.001470000000000 0.001510000000000 0.001386666666667 0.001133333333333 0 0 0 0 0 0 0 0 0.000840000000000 0.002543333333333 0.005856666666667 0.012833333333333 0.025703333333333 0.048463333333333 0.079866666666667 0.108070000000000 0.117543333333333 0.128960000000000 0.131686666666667 0.115226666666667 0.086416666666667 0.056513333333333 0.033430000000000 0.018830000000000 0.010793333333333 0.005996666666667 0.003333333333333 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fit Postprocessing 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!

Translated by