Plot of a fitted normal distribution
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam Danz
2021-3-24
Could you replace the x and y lines with something we can copy-paste into matlab without errors?
采纳的回答
Adam Danz
2021-3-25
编辑:Adam Danz
2021-3-25
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
更多回答(1 个)
David Hill
2021-3-24
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 个评论
Adam Danz
2021-3-25
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fit Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

