how to Draw a circle around a choosen node in a graph ?
조회 수: 14 (최근 30일)
이전 댓글 표시
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 nodes
nodesX(1)=rand*X;
nodesY(1)=rand*Y;
for i=2:N
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;
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;
end
end
h_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 on
for k=1:N;
for j=1:N;
if (k~=j)
d=((nodesX(k)-nodesX(j))^2+(nodesY(k)-nodesY(j))^2)^0.5;
end
if (k~=j);
if(d < 50);
line([nodesX(k),nodesX(j)],[nodesY(k),nodesY(j)]);
end
end
end;
end;
댓글 수: 0
채택된 답변
Konstantinos Sofos
2015년 3월 14일
편집: Konstantinos Sofos
2015년 3월 14일
Hi,
I cannot understand fully your question or what do you want to generate. You could use a simple function to plot a circle on the given graph by giving circle center x,y and the radius r. e.g.
function circle(x,y,r)
%x and y are the coordinates of the center of the circle
%r is the radius of the circle
%0.01 is the angle step, bigger values will draw the circle faster but
%you might notice imperfections (not very smooth)
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
plot(x+xp,y+yp,'k');
end
or you could use a simple marker
plot(nodesX(14),nodesY(14),'o','MarkerEdgeColor','k','MarkerSize',15)
plot(nodesX(14),nodesY(14),'o','MarkerEdgeColor','k','MarkerSize',50)
node 14 is with marker and node 12 using circle function with r = 1 meter i.e.
circle(nodesX(12),nodesY(12),1)
Regards,
%
추가 답변 (1개)
Mohammad Mousavi
2020년 10월 24일
Hi
You can use circle marker at the marked point as:
plot([x],[y],'o')
Then, size, linewidth and color can be adjusted by a right click on the plotted marker.
If your MATLAB is older, all the properties of the figure can be found in the Figure Properties window.
Best,
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!