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

1 Ansicht (letzte 30 Tage)
Dhruba Sunuwar
Dhruba Sunuwar am 3 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.
  2 Kommentare
Hank
Hank am 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jeff Miller
Jeff Miller am 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

Ramkrishna Paudel
Ramkrishna Paudel am 28 Feb. 2021
@Dhruba Sunuwar Did you get it ??

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by