Borrar filtros
Borrar filtros

Distance from center to the points

34 visualizaciones (últimos 30 días)
Adeena Naeem
Adeena Naeem el 27 de Ag. de 2019
Comentada: Star Strider el 28 de Ag. de 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.

Respuesta aceptada

Star Strider
Star Strider el 27 de Ag. de 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 comentarios
Adeena Naeem
Adeena Naeem el 28 de Ag. de 2019
Many many thanks!
Star Strider
Star Strider el 28 de Ag. de 2019
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by