Reputation: 53
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:
and Figure 3 shows:
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.
Upvotes: 2
Views: 1622
Reputation: 4549
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.
Upvotes: 4