About half of the values of ‘x0’ and ‘y0’ will be negative.
clear all; X=200; Y=200; Num=10; n=10; Loc_Nodes=zeros(2,Num); for i=1:2 x0=rand(1,Num)*X; y0=rand(1,Num)*Y; Loc_Nodes(1,:)=x0; Loc_Nodes(2,:)=y0; end r= randsample(n,1); while(r<11) for j=1:10 %k=[0,20,30,45,60,90,120,135,150,160,180,200,210,225,240,270,290,300,315,330,360]; r= randsample(n,1); theta=360*rand; [x,y]=pol2cart(deg2rad(theta),r); x0=x0+x; y0=y0+y; Loc_Nodes(1,:)=x0; Loc_Nodes(2,:)=y0; scatter( Loc_Nodes(1,:), Loc_Nodes(2,:),'filled'); xlim ([0 210]) ylim ([0 210]) xticks(0:10:200) yticks(0:10:200) drawnow; pause(1) end end
Kshitij Singh answered .
2025-11-20
x0 = (0.5-rand(1,Num))*X;
y0 = (0.5-rand(1,Num))*Y;