Cumulative distribution function
collapse all in page
Syntax
y = cdf(name,x,A)
y = cdf(name,x,A,B)
y = cdf(name,x,A,B,C)
y = cdf(name,x,A,B,C,D)
y = cdf(pd,x)
y = cdf(___,'upper')
Description
y = cdf(name,x,A)
returns the cumulative distribution function (cdf) for the one-parameter distribution family specified by name
and the distribution parameter A
, evaluated at the values in x
.
example
y = cdf(name,x,A,B)
returns the cdf for the two-parameter distribution family specified by name
and the distribution parameters A
and B
, evaluated at the values in x
.
y = cdf(name,x,A,B,C)
returns the cdf for the three-parameter distribution family specified by name
and the distribution parameters A
, B
, and C
, evaluated at the values in x
.
y = cdf(name,x,A,B,C,D)
returns the cdf for the four-parameter distribution family specified by name
and the distribution parameters A
, B
, C
, and D
, evaluated at the values in x
.
example
y = cdf(pd,x)
returns the cdf of the probability distribution object pd
, evaluated at the values in x
.
y = cdf(___,'upper')
returns the complement of the cdf using an algorithm that more accurately computes the extreme upper-tail probabilities. 'upper'
can follow any of the input arguments in the previous syntaxes.
Examples
collapse all
Compute Normal Distribution cdf by Specifying Distribution Name and Parameters
Open Live Script
Compute the cdf values for a normal distribution by specifying the distribution name 'Normal'
and the distribution parameters.
Define the input vector x to contain the values at which to calculate the cdf.
x = [-2,-1,0,1,2];
Compute the cdf values for the normal distribution with the mean equal to 1 and the standard deviation equal to 5.
mu = 1;sigma = 5;y = cdf('Normal',x,mu,sigma)
y = 1×5 0.2743 0.3446 0.4207 0.5000 0.5793
Each value in y corresponds to a value in the input vector x. For example, at the value x equal to 1, the corresponding cdf value y is equal to 0.5000.
Compute Normal Distribution cdf Using Distribution Object
Create a normal distribution object and compute the cdf values of the normal distribution using the object.
Create a normal distribution object with the mean equal to 1 and the standard deviation equal to 5.
mu = 1;sigma = 5;pd = makedist('Normal','mu',mu,'sigma',sigma);
Define the input vector x to contain the values at which to calculate the cdf.
x = [-2,-1,0,1,2];
Compute the cdf values for the normal distribution at the values in x.
y = cdf(pd,x)
y = 1×5 0.2743 0.3446 0.4207 0.5000 0.5793
Each value in y corresponds to a value in the input vector x. For example, at the value x equal to 1, the corresponding cdf value y is equal to 0.5000.
Compute Poisson Distribution cdf
Open Live Script
Create a Poisson distribution object with the rate parameter, , equal to 2.
lambda = 2;pd = makedist('Poisson','lambda',lambda);
Define the input vector x to contain the values at which to calculate the cdf.
x = [0,1,2,3,4];
Compute the cdf values for the Poisson distribution at the values in x.
y = cdf(pd,x)
y = 1×5 0.1353 0.4060 0.6767 0.8571 0.9473
Each value in y corresponds to a value in the input vector x. For example, at the value x equal to 3, the corresponding cdf value y is equal to 0.8571.
Alternatively, you can compute the same cdf values without creating a probability distribution object. Use the cdf
function, and specify a Poisson distribution using the same value for the rate parameter, .
y2 = cdf('Poisson',x,lambda)
y2 = 1×5 0.1353 0.4060 0.6767 0.8571 0.9473
The cdf values are the same as those computed using the probability distribution object.
Plot Standard Normal Distribution cdf
Open Live Script
Create a standard normal distribution object.
pd = makedist('Normal')
pd = NormalDistribution Normal distribution mu = 0 sigma = 1
Specify the x
values and compute the cdf.
x = -3:.1:3;p = cdf(pd,x);
Plot the cdf of the standard normal distribution.
plot(x,p)
Plot Gamma Distribution cdf
Open Live Script
Create three gamma distribution objects. The first uses the default parameter values. The second specifies a = 1
and b = 2
. The third specifies a = 2
and b = 1
.
pd_gamma = makedist('Gamma')
pd_gamma = GammaDistribution Gamma distribution a = 1 b = 1
pd_12 = makedist('Gamma','a',1,'b',2)
pd_12 = GammaDistribution Gamma distribution a = 1 b = 2
pd_21 = makedist('Gamma','a',2,'b',1)
pd_21 = GammaDistribution Gamma distribution a = 2 b = 1
Specify the x
values and compute the cdf for each distribution.
x = 0:.1:5;cdf_gamma = cdf(pd_gamma,x);cdf_12 = cdf(pd_12,x);cdf_21 = cdf(pd_21,x);
Create a plot to visualize how the cdf of the gamma distribution changes when you specify different values for the shape parameters a
and b
.
figure;J = plot(x,cdf_gamma);hold on;K = plot(x,cdf_12,'r--');L = plot(x,cdf_21,'k-.');set(J,'LineWidth',2);set(K,'LineWidth',2);legend([J K L],'a = 1, b = 1','a = 1, b = 2','a = 2, b = 1','Location','southeast');hold off;
Fit Pareto Tails to t Distribution and Compute the cdf
Open Live Script
Fit Pareto tails to a distribution at cumulative probabilities 0.1 and 0.9.
t = trnd(3,100,1);obj = paretotails(t,0.1,0.9);[p,q] = boundary(obj)
p = 2×1 0.1000 0.9000
q = 2×1 -1.8487 2.0766
Compute the cdf at the values in q
.
cdf(obj,q)
ans = 2×1 0.1000 0.9000
Input Arguments
collapse all
x
— Values at which to evaluate cdf
scalar value | array of scalar values
Values at which to evaluate the cdf, specified as a scalar value or an array of scalar values.
If one or more of the input arguments x
, A, B, C, and D are arrays, then the array sizes must be the same. In this case, cdf
expands each scalar input into a constant array of the same size as the array inputs. See name for the definitions of A
, B
, C
, and D
for each distribution.
Example: [0.1,0.25,0.5,0.75,0.9]
Data Types: single
| double
Output Arguments
collapse all
y
— cdf values
scalar value | array of scalar values
cdf values, returned as a scalar value or an array of scalar values. y
is the same size as x after any necessary scalar expansion. Each element in y
is the cdf value of the distribution, specified by the corresponding elements in the distribution parameters (A, B, C, and D) or the probability distribution object (pd), evaluated at the corresponding element in x
.
Alternative Functionality
cdf
is a generic function that accepts either a distribution by its namename
or a probability distribution objectpd
. It is faster to use a distribution-specific function, such as normcdf for the normal distribution and binocdf for the binomial distribution. For a list of distribution-specific functions, see Supported Distributions.Use the Probability Distribution Function app to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The input argument
name
must be a compile-time constant. For example, to use the normal distribution, includecoder.Constant('Normal')
in the-args
value of codegen (MATLAB Coder).The input argument
pd
can be a fitted probability distribution object for beta, exponential, extreme value, lognormal, normal, and Weibull distributions. Createpd
by fitting a probability distribution to sample data from the fitdist function. For an example, see Code Generation for Probability Distribution Objects.
For more information on code generation, see Introduction to Code Generation and General Code Generation Workflow.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
expand all
R2023b: Support for Pearson distributions
Starting in R2023b, cdf
supports Pearson distributions.
See Also
pdf | ecdf | icdf | mle | random | makedist | fitdist | Distribution Fitter | paretotails
Topics
- Working with Probability Distributions
- Supported Distributions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office