i need the nodes to move in different direction

Illustration
rehman bin omer Abdul - 2023-03-21T13:44:20+00:00
Question: i need the nodes to move in different direction

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  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

I have no idea what your question is.
 
If you want the rand function to return negative numbers, subtract it from 0.5.
 
Example
 
    x0 = (0.5-rand(1,Num))*X;
    y0 = (0.5-rand(1,Num))*Y;
About half of the values of x0 and y0 will be negative.
 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!