Distance from center to the points

34 次查看(过去 30 天)
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by