matlab画动态图
function[]=main()N=50;t=0:0.0001;x=0:0.21:20;w=Sum(N,t(1));h=plot(x,w,'linewidth',5);...
function[]=main()
N=50;t=0:0.0001;x=0:0.21:20;
w= Sum(N,t(1));
h=plot(x,w,'linewidth',5);
axis([0,20,0,1.5]);
for n=2:length(t)
w=Sum(N,t(n));
set(h,'ydata',w);
drawnow;
pause(0.1)
end
function u=Sum(N,t)
x=0:0.21:20;u=0;
for k=1:2*N
u=u+exp(-(k^2*pi^2*10^2/400*t))*2/k/pi*(cos(k*pi*10/20)-cos(k*pi*11/20))*sin(k*pi*x./20);
end
这个程序画出的应该是一个关于时间t的动态图,结果是一个静态图,求高手解答 展开
N=50;t=0:0.0001;x=0:0.21:20;
w= Sum(N,t(1));
h=plot(x,w,'linewidth',5);
axis([0,20,0,1.5]);
for n=2:length(t)
w=Sum(N,t(n));
set(h,'ydata',w);
drawnow;
pause(0.1)
end
function u=Sum(N,t)
x=0:0.21:20;u=0;
for k=1:2*N
u=u+exp(-(k^2*pi^2*10^2/400*t))*2/k/pi*(cos(k*pi*10/20)-cos(k*pi*11/20))*sin(k*pi*x./20);
end
这个程序画出的应该是一个关于时间t的动态图,结果是一个静态图,求高手解答 展开
1个回答
展开全部
function[]=main()
N=50;t=0:0.0001;x=0:0.21:20; 这里t=0:0.0001:1
w= Sum(N,t(1));
h=plot(x,w,'linewidth',5);
axis([0,20,0,1.5]);
for n=2:length(t)
w=Sum(N,t(n));
set(h,'ydata',w);
drawnow;
pause(0.1)
end
function u=Sum(N,t)
x=0:0.21:20;u=0;
for k=1:2*N
u=u+exp(-(k^2*pi^2*10^2/400*t))*2/k/pi*(cos(k*pi*10/20)-cos(k*pi*11/20))*sin(k*pi*x./20);
end
N=50;t=0:0.0001;x=0:0.21:20; 这里t=0:0.0001:1
w= Sum(N,t(1));
h=plot(x,w,'linewidth',5);
axis([0,20,0,1.5]);
for n=2:length(t)
w=Sum(N,t(n));
set(h,'ydata',w);
drawnow;
pause(0.1)
end
function u=Sum(N,t)
x=0:0.21:20;u=0;
for k=1:2*N
u=u+exp(-(k^2*pi^2*10^2/400*t))*2/k/pi*(cos(k*pi*10/20)-cos(k*pi*11/20))*sin(k*pi*x./20);
end
追问
请问这个动画如何保存
追答
function[]=main()
N=50;
t=0:0.0001:0.005; %这里改小了点 避免视频文件过大
x=0:0.21:20;
aviobj=avifile('test'); %定义一个视频文件用来存动画
aviobj.quality=60;
aviobj.Fps=5;
w= Sum(N,t(1));
h=plot(x,w,'linewidth',5);
axis([0,20,0,1.5]);
for n=2:length(t)
w=Sum(N,t(n));
set(h,'ydata',w);
drawnow;
frame=getframe(gca); %把图像存入视频文件中
im=frame2im(frame);
aviobj=addframe(aviobj,im);
pause(0.1)
end
aviobj=close(aviobj);
function u=Sum(N,t)
x=0:0.21:20;u=0;
for k=1:2*N
u=u+exp(-(k^2*pi^2*10^2/400*t))*2/k/pi*(cos(k*pi*10/20)-cos(k*pi*11/20))*sin(k*pi*x./20);
end
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询