How can I make the random point moves based on locations ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Below there is a point randomly deployed, its moved based on the angles which leads to generate or deply that point in 5 locations according to the number of angles. My question how can I store these 5 positions in a matrix OR can I make index 5 positions in order to move that random point based on position ?? NOTE: The 5 positions that I'm asking about are " newPos " that mentioned in the code below.
Thanks in advance and appreciate any comment
%pointPos = [0 0];
v=2;%7.2/3.6;
%x=plot(pointPos,'*');
NumDrone1=1;center=[0 0];ro1=1000;
theta_Drone1=2*pi*(rand(NumDrone1,1));
g1 = 0.1 * ro1 + 0.1 * ro1 * rand(NumDrone1,1);
PosPoint1_x=center(1)+g1.*cos(theta_Drone1); % Initial positions
PosPoint1_y=center(2)+g1.*sin(theta_Drone1);
PosPoint1 = [PosPoint1_x ,PosPoint1_y]
hfig = figure('Color', 'w');
hax = axes('Parent', hfig);
h(1) = plot(PosPoint1(1,1),PosPoint1(1,2),'Parent', hax,'Marker', '.','Color', 'k','LineStyle', '-','MarkerSize', 12);
hold(hax, 'on')
grid(hax, 'on')
axis(hax, 'equal')
angleOption = [24 56 72 36 96]
for ii = 1:numel(angleOption)
chooseAngle = angleOption(ii)
displacement = [cos(chooseAngle).*v, sin(chooseAngle).*v];
newPos = PosPoint1 + displacement
startpos = newPos-displacement
XData = [h.XData newPos(:, 1)];
YData = [h.YData newPos(:, 2)];
set(h, 'XData', XData, 'YData', YData)
drawnow
XData = [h.XData startpos(:, 1)];
YData = [h.YData startpos(:, 2)];
set(h, 'XData', XData, 'YData', YData)
drawnow
end
0 comentarios
Respuestas (1)
Image Analyst
el 30 de Dic. de 2022
I didn't dig in to your code but it sounds like you want to do a random walk.
See my collection of random walk demos.
To store values in an array you need to index them with the loop counter, like
XData(ii) = newPos(:, 1);
YData(ii) = newPos(:, 2);
and don't do that second set of assignments to XData and YData.
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!