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);
此文件包含电磁波作为两个组成部分:彼此成直角的电场和磁场,它应该向前移动。但它始终保持静止,因为添加帧错误。也许有人可以帮助我?
答案 0 :(得分:1)
您的代码中存在一些错误:
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);
希望这有帮助。