how to make a pdf(probability density function) plot from a cdf(cumulative distributive function) plot?

24 views (last 30 days)
I have a CDF data and plot: my vector is 'on'
CDF_on = ecdf(on);
figure
ecdf(on)
i would like to get a pdf plot from this. i know that pdf values are derivative of cdf values. I try to do this way:
PDF_on=diff(CDF_on);
figure
plot(PDF_on,'-*')
derivative is good I think, but there is something wrong with x axis. My values on PDF plot are supposed to match the values on CDF plot but they dont. Please help? Thanks guys

Answers (1)

Star Strider
Star Strider on 9 Apr 2014
Edited: Star Strider on 9 Apr 2014
Try this:
PDF_on=diff([0 CDF_on]); % CDF_on is a row vector
or
PDF_on=diff([0; CDF_on]); % CDF_on is a column vector
Padding with the initial zero preserves the first element and makes the array sizes of PDF_on and CDF_on equal.
EDIT -- If you want PDF_on as d( CDF_on ) / d(x), do the same diff operation on the x vector, then do an element-by-element divide:
dfdx = diff([0 f]) ./ diff([0 x]);

Tags

Community Treasure Hunt

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

Start Hunting!