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!