# MATLAB how to Draw a circle around a chosen node in a graph?

l have generated a topology of a network with 200 nodes.than l want to draw a circle with black color around a choosen node(satisfying a certain condition IF (condition) ).

to simplify let the user introduce the the index of the node to circle with the black color.

here is my code of the generated topology.l need to add wich instructions to draw the circle around the choosen node ?

``X=100;Y=100;N=200; %number of nodesnodesX(1)=rand*X;nodesY(1)=rand*Y;for i=2:NnodesX(i)=rand*X;nodesY(i)=rand*Y;d(i-1) =((nodesX(i)-nodesX(i-1)).^2+(nodesY(i)-nodesY(i-1)).^2).^0.5;while (d(i-1)>200)nodesX(i)=rand*X;nodesY(i)=rand*Y;d(i-1) =((nodesX(i)-nodesX(i-1)).^2+(nodesY(i)-nodesY(i-1)).^2).^0.5;endendh_old=plot(nodesX,nodesY,'m*');labels=[1:N]';labels=num2str(labels);text(nodesX,nodesY,labels);xlabel('X (Meters)');ylabel('Y (Meters)');title(['Network Topology with',num2str(N),'nodes']);hold onfor k=1:N;for j=1:N;if (k~=j)d=((nodesX(k)-nodesX(j))^2+(nodesY(k)-nodesY(j))^2)^0.5;endif (k~=j);if(d < 50);line([nodesX(k),nodesX(j)],[nodesY(k),nodesY(j)]);endendend;end;``

Define a simple function to draw a circle. A cheap and dirty way is to use polar expressions.

``````function [] = circle(center_x,center_y,r)

theta = 0:0.01:2*pi;
x  = center_x + r*cos(theta);
y = center_y + r*sin(theta);

plot(x,y,'k','LineWidth',2)
``````

Pass this function the `NodeX` and `NodeY` values of the indexed node as the point at which the circle is centered. You can set the radius of the circle as per your choice. Using `r=1` and picking an arbitrary index, I got: 