How to move on a straight line
7 次查看(过去 30 天)
显示 更早的评论
Hello everyone ! I would love to know how to move something in a straight line in Matlab. For example i have an object and i want to move it in a line which is parallel to Y axis . Let's say at the spot X=3 so i have to go straight up by changing the Y numbers.So it will be something like X=3 Y=1 X=3 Y=2 X=3 Y=3 etc Thanks a lot in advance :)
0 个评论
采纳的回答
Walter Roberson
2011-11-24
h = plot(3, 1, 'o', 'MarkerSize', 30);
drawnow
for Y = 2:10
set(h, 'YData', Y);
drawnow
end
2 个评论
Walter Roberson
2011-11-25
http://www.mathworks.com/help/techdoc/ref/drawnow.html
drawnow causes figure windows and their children to update, and flushes the system event queue. Any callbacks generated by incoming events (e.g., mouse or key events) are dispatched before drawnow returns.
(In other words, draw the changed graph on the screen)
http://www.mathworks.com/help/techdoc/ref/for.html
(the loop will be repeated, altering Y from 2 to 10 by 1's)
http://www.mathworks.com/help/techdoc/ref/set.html
http://www.mathworks.com/help/techdoc/ref/line_props.html
(the Y coordinate associated with the line will be altered, thus moving the object vertically)
(and then the drawnow to cause the screen to be updated with the new location)
You might want to change the drawnow calls to pause(1) calls to tell it to update the screen and then wait for 1 second, so that you can see more obviously the changes in the Y coordinate.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!