How to move on a straight line

7 vues (au cours des 30 derniers jours)
Nikolaos
Nikolaos le 24 Nov 2011
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 :)

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Nov 2011
h = plot(3, 1, 'o', 'MarkerSize', 30);
drawnow
for Y = 2:10
set(h, 'YData', Y);
drawnow
end
  2 commentaires
Nikolaos
Nikolaos le 24 Nov 2011
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 le 25 Nov 2011
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.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by