# Draw PDF and CDF of random values of distance from a 10X10 matrix

4 views (last 30 days)
Dhruba Sunuwar on 3 Jun 2020
Commented: Dhruba Sunuwar on 5 Jun 2020
I have been given an assignment to write a code on MATLAB for the following:
1. Distribute 10 nodes in a 1 km*1 km two-dimensional area:
• The positions of the 10 nodes are random every time the code is runs
• Each of X and Y is uniformly distributed
2. Draw a PDFand a CDF of the Euclidean distances among all the nodes
• A 10-by-10 matrix will suffice these distances
• wherein the distance to itself will be 0
I am able to calculate the distances between the randomly distributed nodes but I can't find a way to plot the PDF and CDF of the calculated distances values. Can someone help me out how to find the PDF and CDF? I am new to MATLAB and so far, I have come up with the script as shown in the figure I have attached here.

Hank on 3 Jun 2020
If you're looking for some kind of plot_pdf function, I don't think it exists. Use the definition of PDF as it applies to a discrete set to generate what you need.
Dhruba Sunuwar on 5 Jun 2020
thank you for the help

Jeff Miller on 4 Jun 2020
I'm guessing you want the empirical PDF and CDF functions (that will change slightly every time you rerun the code, due to random variation). You can get something close to the empirical PDF with
histogram(D)
If you have the stats toolbox, you could use ksdensity() to make a nicer smooth plot.
Look at the function 'ecdf' for getting the empirical CDF

#### 1 Comment

Dhruba Sunuwar on 5 Jun 2020
thank you