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 :)

采纳的回答

Walter Roberson
Walter Roberson 2011-11-24
h = plot(3, 1, 'o', 'MarkerSize', 30);
drawnow
for Y = 2:10
set(h, 'YData', Y);
drawnow
end
  2 个评论
Nikolaos
Nikolaos 2011-11-24
Hello Walter and thanks a lot for your answer ! As i am really new to Matlab can you please describe me what that program really does ?
I understand that you give it the initial spot which is x=3 and y=1 (when i run it ,it shows that i am at x=3 y=10) and it puts an "o" there ,with mastersize you give its size.
Then what does that command "drawnow" does exactly ?
That for loop means that it does the same thing up to ten (or five) times ? And i don't understand that set commnand too. :(
Thanks a lot for your time again . Looking forward to your response again :)
Walter Roberson
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 个)

Nikolaos
Nikolaos 2011-11-25
Thanks a lot for your time and effort Walter! I appreciate it a lot :)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by