[求助]小弟初学MATLAB,请大虾帮个小忙,谢谢
v0=.2;R=1;t=0:.05:6*R*pi/v0;
x0=0;y0=0;
sita=0:pi/20:2*pi;
cx=R*sin(sita);
cy=R*cos(sita)+R;
xt=v0*t;
x=v0*t-R*sin(v0/R*t);
y=R-R*cos(v0/R*t);
% plot(x,y);
line([0,6*R*pi],[0,0],'color','y');
title('MatLab动画:摆线运动');
axis([-R,20,0,10]);
axis('off','equal');%
point=line(x0,y0,'color','b','linestyle','.','erasemode','none','markersize',5);
circle0=line(cx,cy,'color','r','linestyle','--','erasemode','xor','markersize',1);%
line0=line([0,0],[R,0],'color','r','linestyle','-','erasemode','xor','markersize',1);%
n=length(t);
i=1;
while 1 %条件表达式
temp=xt(i);
set(circle0,'xdata',cx+temp);drawnow;
set(line0,'xdata',[temp,x(i)],'ydata',[R,y(i)]);drawnow;
set(point,'xdata',x(i),'ydata',y(i));
drawnow;
if i==n
di=-1;set(point,'erasemode','background');
end
if i==1
di=1;set(point,'erasemode','none');
end
i=i+di;
end
小弟初学MATLAB,有一动画仿真,苦于所用教材之中没有这方面的解释,又苦于MATLAB软件太大,一时装不上,特请各位大虾帮注释一下,各句代码的意思或功能,我好举一反三。先谢谢各位了哈。
x0=0;y0=0;
sita=0:pi/20:2*pi;
cx=R*sin(sita);
cy=R*cos(sita)+R;
xt=v0*t;
x=v0*t-R*sin(v0/R*t);
y=R-R*cos(v0/R*t);
% plot(x,y);
line([0,6*R*pi],[0,0],'color','y');
title('MatLab动画:摆线运动');
axis([-R,20,0,10]);
axis('off','equal');%
point=line(x0,y0,'color','b','linestyle','.','erasemode','none','markersize',5);
circle0=line(cx,cy,'color','r','linestyle','--','erasemode','xor','markersize',1);%
line0=line([0,0],[R,0],'color','r','linestyle','-','erasemode','xor','markersize',1);%
n=length(t);
i=1;
while 1 %条件表达式
temp=xt(i);
set(circle0,'xdata',cx+temp);drawnow;
set(line0,'xdata',[temp,x(i)],'ydata',[R,y(i)]);drawnow;
set(point,'xdata',x(i),'ydata',y(i));
drawnow;
if i==n
di=-1;set(point,'erasemode','background');
end
if i==1
di=1;set(point,'erasemode','none');
end
i=i+di;
end