Main Content

unidpdf

Discrete uniform probability density function

Description

p = unidpdf(x,n) returns the probability density function (pdf) of the discrete uniform distribution with the maximum value n, evaluated at the values in x.

example

Examples

collapse all

Compute the probability density function (pdf) of the discrete uniform distribution with the maximum value n=5, for integer values between 0 and 5.

x = 0:1:5;
n = 5;
p = unidpdf(x,n);

Plot the pdf. Use blue circle markers.

plot(x,p,"o",MarkerFaceColor="b")
grid on
xlabel("x")
ylabel("p")

Figure contains an axes object. The axes object with xlabel x, ylabel p contains a line object which displays its values using only markers.

The plot shows that p=0.2 for integer values of x greater than or equal to 1.

Input Arguments

collapse all

Values at which to evaluate the discrete uniform pdf, specified as a nonnegative scalar or an array of nonnegative scalars. The values of x do not need to be integers.

To evaluate the pdf at multiple values, specify x as an array. To evaluate the pdfs of multiple distributions, specify n as an array. If x and n are both arrays, they must have the same size. If only x or n is an array, unidpdf expands the other input argument into a constant array of the same size as the array input. Each element in p is the pdf value of the distribution specified by the corresponding element in n, evaluated at the corresponding element in x.

Data Types: single | double

Maximum value in the discrete uniform distribution, specified as a positive integer or an array of positive integers.

To evaluate the pdf at multiple values, specify x as an array. To evaluate the pdfs of multiple distributions, specify n as an array. If x and n are both arrays, they must have the same size. If only x or n is an array, unidpdf expands the other input argument into a constant array of the same size as the array input. Each element in p is the pdf value of the distribution specified by the corresponding element in n, evaluated at the corresponding element in x.

Data Types: single | double

Output Arguments

collapse all

Discrete uniform pdf values, returned as a numeric scalar or array. p is the same size as x and n after any necessary scalar expansion. Each element in p is the pdf value of the distribution specified by the corresponding element in n, evaluated at the corresponding element in x.

More About

collapse all

Alternative Functionality

  • unidpdf is a function specific to the discrete uniform distribution. Statistics and Machine Learning Toolbox™ also offers the generic function pdf, which supports various probability distributions. To use pdf, specify the probability distribution name and its parameters. Note that the distribution-specific function unidpdf is faster than the generic function pdf.

  • Use the Probability Distribution Function Tool to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a