About half of the values of ‘x0’ and ‘y0’ will be negative.
Question
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
Kshitij Singh
PhD Expert
Answered Nov 20, 2025
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;
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related random mobility Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →