フィルターのクリア

Distance from center to the points

34 ビュー (過去 30 日間)
Adeena Naeem
Adeena Naeem 2019 年 8 月 27 日
コメント済み: Star Strider 2019 年 8 月 28 日
I need the distance to the points (first generated point will be point 1 and so on) from the centre (0,0) from the graph generated by the code below:
**********************************
Code taken from the following Reference: % https://au.mathworks.com/matlabcentral/answers/315717-poisson-point-process-with-fixed-n
r=1; %radius of disk
xx0=0; yy0=0; %centre of disk
%Simulate binomial point process
pointsNumber=5;
theta=2*pi*(rand(pointsNumber,1)); %angular coordinates
rho=r*sqrt(rand(pointsNumber,1)); %radial coordinates
%Convert from polar to Cartesian coordinates
[xx,yy]=pol2cart(theta,rho); %x/y coordinates of Poisson points
%Shift centre of disk to (xx0,yy0)
xx=xx+xx0
yy=yy+yy0
% X = [0,0;xx,yy];
% d = pdist(X,'euclidean')
%Plotting
scatter(xx,yy);
xlabel('x');ylabel('y');
axis square;
**************************************************
Any assistance would be highly appreciated.

採用された回答

Star Strider
Star Strider 2019 年 8 月 27 日
Add this line to your code just after the pol2cart call:
D = pdist2([0 0], [xx, yy]); % Distance
If you want to display the distances on your plot, add these lines after the axis square call:
tc = sprintfc(' %.2f',D); % Display Distances
text(xx, yy, tc, 'HorizontalAlignment','left') % Display Distances
You can also experiment with this:
set(gca, 'XAXisLocation','origin', 'YAXisLocation','origin')
Put it just after the scatter call.
  2 件のコメント
Adeena Naeem
Adeena Naeem 2019 年 8 月 28 日
Many many thanks!
Star Strider
Star Strider 2019 年 8 月 28 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by