Draw PDF and CDF of random values of distance from a 10X10 matrix
2 ビュー (過去 30 日間)
古いコメントを表示
I have been given an assignment to write a code on MATLAB for the following:
- 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 件のコメント
Hank
2020 年 6 月 3 日
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.
回答 (2 件)
Jeff Miller
2020 年 6 月 4 日
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!