Plot smooth cumulative distribution function using MATLAB

巧了我就是萌 提交于 2019-12-20 03:14:51

问题


How is it possible to make the following cumulative distribution function (CDF) curve smoother?

Here's my code, using cdfplot:

clear all; 
close all;
y = [0.75862069 0.666666667 0.882352941 0.875 0.736842105 0.566666667 0.703703704 0.6 0 0.730769231 0.714285714 0.625 0.675 0.693877551 0.731707317 0.558823529 0.679245283 0.740740741 0.785714286 0.789473684 0.615384615 0.6 0.739130435 0.576923077 0 0.75];
cdfplot(y)

The plot looks like:


回答1:


data = [2 1 4 2 3];
sdata = sort(data);
plot(sdata,(0.5:length(sdata))./length(sdata),'-');



回答2:


data = [1 2 2 3 4];
dsum = sum(data);
normalized_data = data/dsum;

cdf = data;

for i = 1:length(data)
    cdf(i) = sum(normalized_data(1:i));
end

plot(cdf);

Is this what you are looking for?




回答3:


You can use the function ecdf:

[f,x] = ecdf(y);
plot(x,f);



回答4:


There is one method. But I consider it as a kind of cheating. Use it with your own responsibility. you can try cdfplot([x,x+a*randn(length(x),1)]). You can play with parameter a, but I suggest you to use value around 0.5. Cheers.



来源:https://stackoverflow.com/questions/7669080/plot-smooth-cumulative-distribution-function-using-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!