繁体   English   中英

未定义的函数或变量“ addframe”

[英]Undefined function or variable 'addframe'

 clear all
 close all

 mov=VideoWriter('mult.avi');

 N=50;
 om=0.1;
 X = linspace(0,12.4,N);
 Y = 0*X;
 Z2= 0*X;

 for it=1:100

 Z = cos(X-it*om);
 Y2= cos(X-it*om);

 stem3(X,Y,Z,'r','fill')
 hold on
 stem3(X,Y2,Z2,'k','fill')
 hold on;
 line(X,Y,Z2);

 for ix=1:N
  hold on;
  plot([X(ix) X(ix)],[0 Y2(ix)],'k');
 end;

 hold off
 view(-25,30);

 xlim([X(1) X(end)]);
 ylim([-1 1])
 zlim([-1 1])

 set(gcf,'Color',[1 1 1],'nextplot','replacechildren', 'Visible','off')

 axis off

 FF=getframe(gcf);

 mov=addframe(mov,FF);
 end;


 mov=close(mov);

这是我的matlab代码。 每当我在命令窗口中单击运行时,我都会看到此错误

 Undefined function or variable 'addframe'.

 Error in EM (line 41)
 mov=addframe(mov,FF); 

该文件包含电磁波两个部分:彼此成直角的电场和磁场,它应该向前移动。 但是它会一直保持静止,因为addframe错误。 那么也许有人可以帮助我吗?

您的代码中有几个错误:

  • 如果使用VideoWriter类,则必须实际打开影片文件(调用open方法),因为VideoWriter仅构造一个VideoWriter object ,将视频数据写入压缩的AVI文件中
  • 另外,使用VideoWriter您必须调用方法writeVideo (而不是addframe (这不是VideoWriter方法)
  • 然后,在脚本末尾(在影片注册的末尾),您必须使用close方法关闭AVI文件

功能addframe可用于帧添加到avifile object与函数创建avifile ; 请注意,此功能将在以后的版本中删除。

此后,您可以找到更新的脚本。

clear all
close all

mov=VideoWriter('mult_1.avi');
% Added 
open(mov);

N=50;
om=0.1;
X = linspace(0,12.4,N);
Y = 0*X;
Z2= 0*X;

for it=1:100

   Z = cos(X-it*om);
   Y2= cos(X-it*om);

   stem3(X,Y,Z,'r','fill')
   hold on
   stem3(X,Y2,Z2,'k','fill')
   hold on;
   line(X,Y,Z2);

   for ix=1:N
      hold on;
      plot([X(ix) X(ix)],[0 Y2(ix)],'k');
   end;

   hold off
   view(-25,30);

   xlim([X(1) X(end)]);
   ylim([-1 1])
   zlim([-1 1])

   set(gcf,'Color',[1 1 1],'nextplot','replacechildren', 'Visible','off')

   axis off

   FF=getframe(gcf);
   % With "VideoWriter" use "writevideo" to add frames to the video
   writeVideo(mov,FF);

end;
% Close the video file
close(mov);

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM