注册 登录
编程论坛 Matlab

[求助]小弟初学MATLAB,请大虾帮个小忙,谢谢

SuperStar515 发布于 2007-01-07 14:46, 1131 次点击
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软件太大,一时装不上,特请各位大虾帮注释一下,各句代码的意思或功能,我好举一反三。先谢谢各位了哈。
6 回复
#2
SuperStar5152007-01-07 21:06
不能掉下去,大虾们帮忙啊
#3
SuperStar5152007-01-08 18:26
#4
zhangenter2007-01-12 22:20
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); % sin^2+cos^2=1,构造圆
cy=R*cos(sita)+R;
xt=v0*t;
x=v0*t-R*sin(v0/R*t); % sin^2+cos^2=1,构造圆
y=R-R*cos(v0/R*t);
% plot(x,y);
line([0,6*R*pi],[0,0],'color','y'); % 黄线连接[0,0]和[6*R*pi,0]
title('MatLab动画:摆线运动'); % 设置标题
axis([-R,20,0,10]); % 设置坐标范围
axis('off','equal'); % 隐藏坐标轴,同时将X轴和Y轴设置为等比例度
point=line(x0,y0,'color','b','linestyle','.','erasemode','none','markersize',5);
% 画蓝点,图形重叠时覆盖但不擦除,蓝点大小为5象素
circle0=line(cx,cy,'color','r','linestyle','--','erasemode','xor','markersize',1);
% 画红虚线连接cx,cy构成的点(即一个圆),图形重叠时只显示不覆盖,大小为1象素
line0=line([0,0],[R,0],'color','r','linestyle','-','erasemode','xor','markersize',1);
% 画红实线连接[0,R]和[0,0]图形重叠时只显示不覆盖,大小为1象素
n=length(t);
i=1;
while 1 %条件表达式
temp=xt(i);
set(circle0,'xdata',cx+temp);drawnow;
% 红虚线构成的圆,整体向右偏移temp的距离
set(line0,'xdata',[temp,x(i)],'ydata',[R,y(i)]);drawnow;
% 红实线连接的点的变为[temp,R]和[x(i),y(i)],即圆心和蓝点
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
% erasemode的四种模式可能搞混了,自有空己去看下帮助吧
#5
SuperStar5152007-01-12 22:56
非常非常感谢,顶版主
#6
zhangenter2007-01-12 23:10

写了段代码证明自己erasemode的四种模式确实搞错了

figure( 'doublebuffer', 'on') ;
axes( 'pos', [0,0,1,1] ) ;
axis( [-1.1 1.1 -1.1 1.1] ) ;
axis('off','equal');
hold on;
t=0:0.01:2*pi;
plot(sin(t),cos(t)) ;
L = plot(0,1,'r.') ;
set(L,'markersize',30,'tag','ball') ;
c = 0 ;
uicontrol('style','pushbutton','pos',[10 10 80 20], 'str','normal','cal','set(findobj(gcf,''tag'',''ball''),''erasemode'',''normal'')') ;
uicontrol('style','pushbutton','pos',[10 35 80 20], 'str','background','cal','set(findobj(gcf,''tag'',''ball''),''erasemode'',''background'')') ;
uicontrol('style','pushbutton','pos',[10 60 80 20], 'str','none','cal','set(findobj(gcf,''tag'',''ball''),''erasemode'',''none'')') ;
uicontrol('style','pushbutton','pos',[10 85 80 20], 'str','xor','cal','set(findobj(gcf,''tag'',''ball''),''erasemode'',''xor'')') ;
handles = guihandles( gcf ) ;
guidata(gcf,handles) ;
while(ishandle(L))
set( L,'XData',sin(c),'YData',cos(c) );
pause(0.01);
if c + 0.01 >= 2 * pi
c = 0 ;
else
c = c + 0.01;
end
end

#7
SuperStar5152007-01-12 23:35
这个我自己改吧,麻烦版主了哈
再次感谢!
1