To calculate the cumulative distribution function (CDF) from discrete values in MATLAB, you can use the ecdf
function, which computes the empirical cumulative distribution function (ECDF) for a set of sample points. Here's an example:
main.m239 chars13 lines
In this example, x
and p
define a discrete distribution with five possible values and corresponding probabilities. The ecdf
function is called with two arguments: x
and the 'frequency'
option, indicating that the probabilities should be used as weights for each sample point. The outputs f
and x_values
contain the values of the ECDF and the corresponding x-points, respectively. Finally, the CDF is plotted using the stairs
function.
Note that the CDF is a step function for discrete distributions, which means that its value remains constant between each x-value.
gistlibby LogSnag