请问谁能将这个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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 09:11:16
请问谁能将这个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
请问谁能将这个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
请问谁能将这个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
可以先开一个视频写对象,
writerObj = VideoWriter('peaks.avi');
open(writerObj);
之后在循环里把每一帧加进去
frame = getframe;
writeVideo(writerObj,frame);
最后关闭
close(writerObj);