请问谁能将这个matlab仿真动画保存为gif或者是avi格式啊?主程序已经编好了。。
clear,rm=2;r=0.01:0.02:rm;
th=linspace(0,2*pi,300);
[R,TH]=meshgrid(r,th);
[X,Y]=pol2cart(TH,R);
eth=-3:0.3:3;
rh=0.5:0.1:rm;phi=(0:10:350)*pi/180;
[RH,PHI]=meshgrid(rh,phi);
[XH,YH]=pol2cart(PHI,RH);
figure,fs=16;t=0;
while 1
if get(gcf,'CurrentCharacter')==char(27)return;end
Eth=cos(TH).*cos(2*pi*(t-R))./R;
contour(X,Y,Eth,eth,'r','LineWidth',2)
HPHI=cos(PHI).*cos(2*pi*(t-RH))./RH;
L=HPHI>0;hold on
plot(XH(L),YH(L),'x','Markersize',9)
plot(XH(~L),YH(~L),'.','Markersize',12)
grid on,axis equal
xlabel('\itx/\lambda','FontSize',fs)
ylabel('\ity/\lambda','FontSize',fs)
title('电偶极子辐射电磁场的电场分量传播','FontSize',fs)
drawnow
if t==0 pause,end
t=t+0.02;hold off
end
谢谢各位了 展开
function Electronic_field
clear,rm=2;r=0.01:0.02:rm;
th=linspace(0,2*pi,300);
[R,TH]=meshgrid(r,th);
[X,Y]=pol2cart(TH,R);
eth=-3:0.3:3;
rh=0.5:0.1:rm;phi=(0:10:350)*pi/180;
[RH,PHI]=meshgrid(rh,phi);
[XH,YH]=pol2cart(PHI,RH);
figure,fs=16;t=0;j=0;
filename='test.gif';
while 1
if get(gcf,'CurrentCharacter')==char(27)return;end
Eth=cos(TH).*cos(2*pi*(t-R))./R;
contour(X,Y,Eth,eth,'r','LineWidth',2)
HPHI=cos(PHI).*cos(2*pi*(t-RH))./RH;
L=HPHI>0;hold on
plot(XH(L),YH(L),'x','Markersize',9)
plot(XH(~L),YH(~L),'.','Markersize',12)
grid on,axis equal
xlabel('\itx/\lambda','FontSize',fs)
ylabel('\ity/\lambda','FontSize',fs)
title('电偶极子辐射电磁场的电场分量传播','FontSize',fs)
drawnow
if t==0
pause,
end
t=t+0.02;
j=j+1
frame=getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if j == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
hold off
end
writerObj = VideoWriter('peaks.avi');
open(writerObj);
之后在循环里把每一帧加进去
frame = getframe;
writeVideo(writerObj,frame);
最后关闭
close(writerObj);
这位大婶能否帮着做一下?感激不尽
while的条件里其实是通过t控制视频的时间长短。不过时间上长短不太准确。
clear,rm=2;r=0.01:0.02:rm;
writerObj = VideoWriter('peaks.avi');
open(writerObj);
th=linspace(0,2*pi,300);
[R,TH]=meshgrid(r,th);
[X,Y]=pol2cart(TH,R);
eth=-3:0.3:3;
rh=0.5:0.1:rm;phi=(0:10:350)*pi/180;
[RH,PHI]=meshgrid(rh,phi);
[XH,YH]=pol2cart(PHI,RH);
figure,fs=16;t=0;
while t<10
if get(gcf,'CurrentCharacter')==char(27)return;end
Eth=cos(TH).*cos(2*pi*(t-R))./R;
contour(X,Y,Eth,eth,'r','LineWidth',2)
HPHI=cos(PHI).*cos(2*pi*(t-RH))./RH;
L=HPHI>0;hold on
plot(XH(L),YH(L),'x','Markersize',9)
plot(XH(~L),YH(~L),'.','Markersize',12)
grid on,axis equal
xlabel('\itx/\lambda','FontSize',fs)
ylabel('\ity/\lambda','FontSize',fs)
title('电偶极子辐射电磁场的电场分量传播','FontSize',fs)
drawnow
% if t==0 pause,end
t=t+0.02;
frame = getframe;
writeVideo(writerObj,frame);
hold off
end
close(writerObj);