2015-10-17 146 views
0
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代碼。每次我打在命令窗口中運行,我看到這個錯誤未定義函數或變量'addframe'

Undefined function or variable 'addframe'. 

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

此文件包含電磁波的兩個組成部分:直角彼此的電場和磁場,它應該向前推進。但它始終保持不變,因爲addframe錯誤。所以也許有人可以幫助我?

+0

你可以發佈'addframe'函數的來源嗎? – kvorobiev

+0

什麼來源?這是所有我得到:( – TheDude

+0

功能'addframe'定義? – kvorobiev

回答

1

有一對夫婦在代碼中的錯誤:

  • 如果你使用VideoWriter類,你必須真正打開電影文件(調用open方法),因爲VideoWriter只有構建了一個VideoWriter object視頻數據寫入壓縮的AVI文件
  • 也使用VideoWriter你要調用的方法writeVideo(而不是addframe(這是不是一個VideoWriter方法
  • 然後,在t結束他腳本(在電影的registraion結束),你必須關閉AVI文件與close方法

功能addframe可用於幀添加到使用功能avifile創建的avifile object;請注意,此功能將在未來版本中刪除。

此後您可以找到更新的腳本。

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); 

希望這會有所幫助。

+0

非常感謝,我可以再問一個問題嗎? 如何讓這個文件在我運行後打開而不是導出? – TheDude

+0

你是什麼意思用_make打開這個文件,而不是在我按下run_之後導出?注意,我編輯了答案,並且添加了一些關於'addframe'的信息:函數addframe可用於將幀添加到使用該函數創建的avifile對象avifile;注意,這個函數將在未來的版本中被刪除。 –

+0

哦好吧srr詢問這樣一個愚蠢的問題:) – TheDude