Plot smooth cumulative distribution function using MATLAB
19,617
Solution 1
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?
Solution 2
data = [2 1 4 2 3];
sdata = sort(data);
plot(sdata,(0.5:length(sdata))./length(sdata),'-');
Solution 3
You can use the function ecdf
:
[f,x] = ecdf(y);
plot(x,f);
Author by
ddayan
Updated on June 05, 2022Comments
-
ddayan almost 2 years
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:
-
Dang Khoa over 12 yearsWhat have you done in attempts to figure out the problem?
-
ddayan over 12 yearsyea:data = [1 1 1 4 5]; %# Sample data p1 = cdf('Normal',data,0,1); plot(p1);
-
SecretAgentMan over 5 yearsThis appears to be an empirical CDF and therefore will not typically be smooth unless altered.
-