필터 지우기
필터 지우기

How to move on a straight line

조회 수: 4 (최근 30일)
Nikolaos
Nikolaos 2011년 11월 24일
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