Main Content


Piecewise linear probability distribution object


A PiecewiseLinearDistribution object consists of a model description for a piecewise linear probability distribution.

The piecewise linear distribution is a nonparametric probability distribution created using a piecewise linear representation of the cumulative distribution function (cdf). The options specified for the piecewise linear distribution specify the form of the cdf. The probability density function (pdf) is a step function.

The piecewise linear distribution uses the following parameters.

xVector of x values at which the cdf changes slope
FxVector of cdf values that correspond to each value in x


Create a PiecewiseLinearDistribution probability distribution with specified parameter values object using makedist.


expand all

Distribution Parameters

Data values at which the cumulative distribution function (cdf) changes slope, specified as a vector of scalar values.

Data Types: single | double

cdf value at each value in x, specified as a vector of scalar values.

Data Types: single | double

Distribution Characteristics

This property is read-only.

Logical flag for truncated distribution, specified as a logical value. If IsTruncated equals 0, the distribution is not truncated. If IsTruncated equals 1, the distribution is truncated.

Data Types: logical

This property is read-only.

Number of parameters for the probability distribution, specified as a positive integer value.

Data Types: double

This property is read-only.

Distribution parameter values, specified as a vector.

Data Types: single | double

This property is read-only.

Truncation interval for the probability distribution, specified as a vector containing the lower and upper truncation boundaries.

Data Types: single | double

Other Object Properties

This property is read-only.

Probability distribution name, specified as a character vector.

Data Types: char

This property is read-only.

Distribution parameter descriptions, specified as a cell array of character vectors. Each cell contains a short description of one distribution parameter.

Data Types: char

This property is read-only.

Distribution parameter names, specified as a cell array of character vectors.

Data Types: char

Object Functions

cdfCumulative distribution function
icdfInverse cumulative distribution function
iqrInterquartile range
meanMean of probability distribution
medianMedian of probability distribution
pdfProbability density function
randomRandom numbers
stdStandard deviation of probability distribution
truncateTruncate probability distribution object
varVariance of probability distribution


collapse all

Create a piecewise linear distribution object using the default parameter values.

pd = makedist('PiecewiseLinear')
pd = 

F(0) = 0
F(1) = 1

Load the sample data. Visualize the patient weight data using a histogram.

load hospital

The histogram shows that the data has two modes, one for female patients and one for male patients.

Compute the empirical cumulative distribution function (ecdf) for the data.

[f,x] = ecdf(hospital.Weight);

Construct a piecewise linear approximation to the ecdf and plot both functions.

f = f(1:5:end); % keep a less dense grid of points
x = x(1:5:end);

hold on
plot(x,f,'ro','MarkerFace','r') % overlay grid
plot(x,f,'k') % show interpolation

Create a piecewise linear probability distribution object using the piecewise approximation of the ecdf.

pd = makedist('PiecewiseLinear','x',x,'Fx',f)
pd = 

F(111) = 0
F(118) = 0.05
F(124) = 0.13
F(130) = 0.25
F(135) = 0.37
F(142) = 0.5
F(163) = 0.55
F(171) = 0.61
F(178) = 0.7
F(183) = 0.82
F(189) = 0.94
F(202) = 1

Generate 100 random numbers from the distribution.

rw = random(pd,100,1);

Plot the random numbers to visually compare their distribution to the original data.


The random numbers generated from the piecewise linear distribution have the same bimodal distribution as the original data.

Introduced in R2013a