How to climb stairs?

4 次查看(过去 30 天)
Nerramus
Nerramus 2016-11-27
回答: Nick 2016-11-27
Hello everyone.
I am a begineer of MATLAB programming and I would like to get a circle climbing the stairs that are written as X and Y.
Here is the code so far:
clc
clear
clf
x=[0 0 29 29 58 58 87];
y=[0 0 0 17 17 34 34];
hbead = line(x(1),y(1),'marker','o','markersize',10,'erase','none') ;
htrail = line(x(1),y(1),'marker','.','color','r','erase','none') ;
axis([-10 90 -5 40]);
axis('square');
for k = 1 : 7
set(hbead ,'xdata',x(k),'ydata',y(k));
set(htrail,'xdata',x(k),'ydata',y(k));
drawnow
end
The circle does not move, nor the tail is drawn. The circle should move according to some equations, which describe how the circle moves when it in vertical or horizontal position, what heppens when the center of circle reaches the stair edge and so on. I guess, that these equations should be written in "for" cycle. Am I right?
Could you please help me to understand what do I do wrong?
Thank you.

回答(1 个)

Nick
Nick 2016-11-27
Try a "pause(0.5)" or something like that in the for loop. Otherwise you only see the last picture.

类别

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