how to change the direction of this code from right falling into left to left falling into right

4 visualizaciones (últimos 30 días)

Respuestas (2)

Naga
Naga el 21 de Ag. de 2024
Editada: Naga el 21 de Ag. de 2024
Hi Lior,
To change the direction of the falling dots from left-to-right to right-to-left, the initial plot position is shifted from (10, 10) to (0, 10) to start from the left. The loop is modified to iterate from 1 to 9 instead of 9 to 1, and the y-coordinate in the plot function is adjusted to 10-y. Please find the modified code below:
plot(0, 10, 'r.', 'markersize', 40)
axis([-1, 11, -1, 11])
for y = 1:9
plot(y,10-y, 'r.', 'markersize', 40)
axis([-1, 11, -1, 11])
pause(0.3)
end
  3 comentarios
Naga
Naga el 21 de Ag. de 2024
Editada: Naga el 21 de Ag. de 2024
I realized I misunderstood your question, so I've revised my response accordingly.

Iniciar sesión para comentar.


Voss
Voss el 21 de Ag. de 2024
figure
x = 1:10;
y = 10:-1:1;
for ii = 1:numel(x)
plot(x(ii),y(ii),'r.','markersize',40)
axis([-1,11,-1,11])
pause(0.3)
end
  1 comentario
Voss
Voss el 21 de Ag. de 2024
Another option:
x = 1:10;
y = 10:-1:1;
figure
ax = gca();
h = line(ax,'Color','r','Marker','.','MarkerSize',40);
set(ax,'XLim',[-1 11],'YLim',[-1 11])
for ii = 1:numel(x)
set(h,'XData',x(ii),'YData',y(ii))
pause(0.3)
end

Iniciar sesión para comentar.

Categorías

Más información sobre Directed Graphs en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by