curve fit gaussian CDF
10 views (last 30 days)
Show older comments
I have 20 data points that follow gaussian CDF and would like to find its mean and standard deviation.
If I understand it correctly, normfit is for gaussian PDF.
So, basically, I am looking for a command like normfit but for gaussian CDF.
I did it in Python but could not find a way to do this in matlab.
The picture below is the result from Python.
y = [ 0.0010 0 0.0020 0.0060 0.0210 0.0400 0.0840 0.1890 0.2790 0.4500 0.6180 0.7550 0.8790 0.9330 0.9770 0.9940 0.9980 1.0000 1.0000 1.0000]
x = [0.3100 0.3115 0.3130 0.3145 0.3160 0.3175 0.3190 0.3205 0.3220 0.3235 0.3250 0.3265 0.3280 0.3295 0.3310 0.3325 0.3340 0.3355 0.3370 0.3385]

And this is the result with curve fit app in matlab.

0 Comments
Accepted Answer
Star Strider
on 23 Aug 2022
Edited: Star Strider
on 23 Aug 2022
Try this —
y = [ 0.0010 0 0.0020 0.0060 0.0210 0.0400 0.0840 0.1890 0.2790 0.4500 0.6180 0.7550 0.8790 0.9330 0.9770 0.9940 0.9980 1.0000 1.0000 1.0000];
x = [0.3100 0.3115 0.3130 0.3145 0.3160 0.3175 0.3190 0.3205 0.3220 0.3235 0.3250 0.3265 0.3280 0.3295 0.3310 0.3325 0.3340 0.3355 0.3370 0.3385];
xv = linspace(min(x), max(x));
ncdf = @(b,x) normcdf(x,b(1),b(2));
ncdfmdl = fitnlm(x,y,ncdf,[0.32 0.01])
B = ncdfmdl.Coefficients.Estimate;
figure
plot(x, y, 'p')
hold on
plot(xv, ncdf(B,xv), '-r')
hold off
grid
.
2 Comments
Star Strider
on 23 Aug 2022
As always, my pleasure!
‘Is there any idea why it is more straight forward in Python?’
I have no experience with Python, so I can only venture a guess. It may be that Python is relatively young and evolved in a different environment, while MATLAB has been around for several decades (my first experience with it was in 1992 and it was not new then) and so it needs to be backward-compatible with legacy code.
.
More Answers (1)
Torsten
on 23 Aug 2022
Edited: Torsten
on 23 Aug 2022
ydata = [ 0.0010 0 0.0020 0.0060 0.0210 0.0400 0.0840 0.1890 0.2790 0.4500 0.6180 0.7550 0.8790 0.9330 0.9770 0.9940 0.9980 1.0000 1.0000 1.0000];
xdata = [0.3100 0.3115 0.3130 0.3145 0.3160 0.3175 0.3190 0.3205 0.3220 0.3235 0.3250 0.3265 0.3280 0.3295 0.3310 0.3325 0.3340 0.3355 0.3370 0.3385];
fun = @(mu,sigma) 0.5*(1+erf((xdata-mu)/(sqrt(2)*sigma)));
fun1 = @(mu,sigma) fun(mu,sigma) - ydata;
sol = lsqnonlin(@(x)fun1(x(1),x(2)),[0.325,0.005]);
mu = sol(1)
sigma = sol(2)
plot(xdata,ydata)
hold on
plot(xdata,fun(mu,sigma))
2 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
