0

I try to plot a CDF graph from a file that has 7914 integers ranging from 0 to 594. But when I plot the graph, it just prints a straight line at 1 like this:

enter image description here

Why does it print a straight line? A CDF graph should be curved like this:

enter image description here

Code:

mu = 0;
sigma = 1;
pd = makedist('Normal',mu,sigma);
fileID = fopen('TLSDeliveryTime.txt', 'r');
formatSpec = '%d';
x1 = fscanf(fileID,formatSpec);
fclose(fileID);
y1 = cdf(pd,x1);
figure
semilogx(x1,y1,'LineWidth',2)
set(gca,'xscale','log')
xlabel('Delivery time (ms)');
ylabel('CDF (%)');
ylim([0, 1]);
legend('X.509');
codeaviator
  • 2,545
  • 17
  • 42
Johan
  • 23
  • 1
  • 5
  • Show us the data. What you get is a valid CCF , depending on the data. Also show the code **in text format** – Ander Biguri May 02 '17 at 10:56
  • @AnderBiguri This is the data file I read from: https://pastebin.com/jGk9wxpq . What is a CCF graph? I want to plot a CDF(Cumulative Distribution Function) graph. Here is the code: https://pastebin.com/rpEAA0Af – Johan May 02 '17 at 11:44
  • A CCF graph is a CDF with a typo :P – Ander Biguri May 02 '17 at 12:07

1 Answers1

0

I think you meant to use a cumulative sum to get your cdf.

mu = 0;
sigma = 1;
pd = makedist('Normal',mu,sigma);
fileID = fopen('TLSDeliveryTime.txt', 'r');
formatSpec = '%d';
x1 = fscanf(fileID,formatSpec);
fclose(fileID);
y1 = cumsum(x1) / sum(x1); %cumulative sum, normalized to 1
figure
semilogx(x1,y1,'LineWidth',2)
set(gca,'xscale','log')
qbzenker
  • 4,412
  • 3
  • 16
  • 23
  • Yeah that looks much better, thank you. But this is a CDF graph even though it looks different than normal CDF graphs when you google CDF? – Johan May 02 '17 at 12:01
  • The way a CDF looks is totally dependent on your distribution type. CDFs can look really "weird" ie not normally distributed if the underlying distribution is not gaussian, which in many cases it is not. All a CDF tells you is the probability that you'll achieve some value that's `<=x`. – qbzenker May 02 '17 at 12:06
  • If this solved your problem, could you mark the check mark next to my answer, plz! – qbzenker May 02 '17 at 12:17
  • I did that, btw should I sort my numbers from lowest to highest before I plot the CDF with that code? I get a graph that looks a little bit weird so wondering if it's the code that is wrong or the data. – Johan May 06 '17 at 13:54