Effacer les filtres
Effacer les filtres

Distance from center to the points

34 vues (au cours des 30 derniers jours)
Adeena Naeem
Adeena Naeem le 27 Août 2019
Commenté : Star Strider le 28 Août 2019
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.

Réponse acceptée

Star Strider
Star Strider le 27 Août 2019
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 commentaires
Adeena Naeem
Adeena Naeem le 28 Août 2019
Many many thanks!
Star Strider
Star Strider le 28 Août 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by