How can I get function expression for Cumulative distribution function

I have a cumulative distribution function(cdf). I have attached the figure. How can I fit the curve and get the function
expression for it?

 Accepted Answer

Likely the easiest way to estimate the parameters is with the Statistics and Machine Learning Toolbox fitdist function:
x = randn(1, 25)*2 + 5; % Create Data (Mean = 5, St Dev = 2)
b = fitdist(x(:), 'normal')
producing:
b =
NormalDistribution
Normal distribution
mu = 5.30768 [4.42359, 6.19177]
sigma = 2.1418 [1.67238, 2.97957]
Choose the appropriate distribution function for your data.

6 Comments

hi, thank you for answer my question.
Actually I already have these mu and sigma value. I would like to derive the function expression for the CDF figure. I have the all the x,y value on the figure.
If you have the mu and sigma values, use the cdf function.
An alternate option using erf:
p = @(x,mu,sigma) (1 + erf((x-mu)/(sigma*sqrt(2))))/2; % Equivalent to ‘normcdf’
hello,thank you for your answering.
I just type this line in MATLAB and use
plot(p);
to compare with the cdf figure see whether it is fit. But MATLAB can not plot p.
Below is the code I use to plot the above cdf figure. x is a 8760*1 matrix.
[mu,sigma] = normfit(x);
d=cdf('norm',x,mu,sigma);
figure
plot(x,d)
Thank you!
You probably have to sort ‘x’ first. (Sorting it has no effect on the parameter estimates, and makes a decent-looking plot possible.)
Try this:
x = sort(x);
[mu,sigma] = normfit(x);
d=cdf('norm',x,mu,sigma);
figure
plot(x,d)
hello, I have try the below code:
x=sort(y,'descend');
[mu,sigma] = normfit(x);
d=cdf('norm',x,mu,sigma);
figure
plot(x,d)
hold on;
p = @(x,mu,sigma) (1 + erf((x-mu)/(sigma*sqrt(2))))/2;
plot(p)
However, it still said plot(p) can not achieved. May I ask what is the "erf" mean?
I provided you with a link to the erf function. It is the error function.
I provided you with the correct code for the plot. Use it!

Sign in to comment.

More Answers (1)

hello,sorry for the late reply.
Can I ask where is he correct code for the plot? I haven't find in the answer.
ask.PNG

1 Comment

It is in this Comment.
Specifically:
x = randn(1, 25)*2 + 5; % Create Data
x = sort(x);
[mu,sigma] = normfit(x);
d=cdf('norm',x,mu,sigma);
figure
plot(x,d)
I did not initially provide the ‘x’ vector, since you have your own. I created it to test my code, and include it here for completeness. (The sort function sorts ascending by default, so there is no need to specify it.)
An alternative using the erf function is:
x = randn(1, 25)*2 + 5; % Create Data
x = sort(x);
[mu,sigma] = normfit(x);
p = @(x,mu,sigma) (1 + erf((x-mu)/(sigma*sqrt(2))))/2; % Equivalent to ‘normcdf’
figure
plot(x,p(x,mu,sigma))

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!