CDF graph doesn't start at x-axis
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi!
I have this code this code:
mu = 0;
sigma = 1;
pd = makedist('Normal',mu,sigma);
fileID1 = fopen('TLSDeliveryTime.txt', 'r');
fileID2 = fopen('X509DeliveryTime.txt', 'r');
fileID3 = fopen('OCSPDeliveryTime.txt', 'r');
formatSpec = '%f';
x1 = fscanf(fileID1,formatSpec);
fclose(fileID1);
nbins=100;
[h, binedges] = hist(x1, nbins);
tlsNormalized = h / sum(h);
cdf = cumsum(tlsNormalized);
semilogx(binedges, cdf,'LineWidth',2);
hold on
x2 = fscanf(fileID2,formatSpec);
fclose(fileID2);
[h2, binedges2] = hist(x2,nbins);
x509Normalized = h2 / sum(h2);
cdf2 = cumsum(x509Normalized);
semilogx(binedges2, cdf2,'LineWidth',2);
hold on
x3 = fscanf(fileID3,formatSpec);
fclose(fileID3);
[h3, binedges3] = hist(x3,nbins);
ocspNormalized = h3 / sum(h3);
cdf3 = cumsum(ocspNormalized);
semilogx(binedges3,cdf3,'LineWidth',2);
hold off
xlabel('Delivery time (ms)');
ylabel('CDF (%)');
ylim([0,1]);
legend('TLS', 'X509', 'OCSP')
And when I plot it, I get this graph:
But do anyone know why it doesn't start at the x-axis? It should start at any percent there in a CDF-graph, but I don't know why my lines doesn't start at x-axis. The TLS line start at 50% for example and this doesn't look like normal CDF's should look like.
0 Kommentare
Antworten (1)
Alain Kuchta
am 11 Mai 2017
I understand that you are plotting the Cumulative Distribution Function of 3 data sets on a semilog plot. The reason the individual plots do not start at the x-axis is because the data is plotted against the bin edges of the histograms on the x-axis. The bin edges do not include zero as the first edge.
There are two options to achieve your desired plot:
1) Set the histogram edges manually to ensure the plots begin at 0. Note that it is recommended to use histogram instead of hist if histogram is available in your release of MATALAB. Refer to the documentation for histogram for more information:
2) Use the cdfplot function from the Statistics and Machine Learning Toolbox to automatically create a cdf plot. Refer to the documentation for cdfplot for more information:
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!