how to make a pdf(probability density function) plot from a cdf(cumulative distributive function) plot?
19 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Star Strider
2014-4-9
编辑:Star Strider
2014-4-9
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]);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!