2

I'm getting a strange looking graph from my cdf function. If I use ecdf, I get the graph I expect. But I get a tangled mess that looks like it contains the right data, but in some wrong order.

SNR = exprnd(1,1000,1); 
Cap = 1*log2(1+SNR); % unit bandwidth

[f,x] = ecdf(Cap);
figure(2);
plot( x,f);

cdf_Cap = cdf('Exponential', Cap, 1);
figure(3);
plot( Cap, cdf_Cap);

figure(4);
cdfplot(Cap);

Figure 2 shows the expected result: enter image description here

and Figure 3 shows: enter image description here

I'm sure its the right data, and just requires some kind of absolute function, or sorting function. I just have no idea what that would be. Any help would be much appreciated.

Duck
  • 53
  • 1
  • 7
  • Just FYI, you don't need to necessarily sort it. You can plot the function without connecting lines like `plot( Cap, cdf_Cap,'o')`, although for the cdf you probably do want to sort it and connect the lines. – JustinBlaber Jul 20 '15 at 03:07

1 Answers1

4

Looks like Cap is not monotonically increasing. I think you might sort it before plotting.

On figure(3), replace this:

plot( Cap, cdf_Cap);

With this:

[~, idx] = sort(Cap);
plot( Cap(idx), cdf_Cap(idx));

Now the data will be plotted in the correct order.

Rafael Monteiro
  • 4,509
  • 1
  • 16
  • 28