cdata在循环的每个步骤中都有不同的变化

时间:2017-01-20 14:34:28

标签: matlab

我正在尝试在Matlab中制作视频,但在运行我的程序后,出现了一条错误消息。 错误说:

    Error using VideoWriter/writeVideo (line 369)
    All 'cdata' fields in FRAMES must be the samse size

我的代码是

    v=VideoWriter('myvideo.avi','Uncompressed AVI'); 
    v.FrameRate=6; 
    open(v)

    startdate=1;
    enddate=10;

    for s=startdate:enddate  
       fig=figure;
       set(fig, 'position',[1 1 750 525])  

       % ....  (plotting of my data )

       g(s)=getframe(fig);
       size(g(s).cdata)
       close(fig)
    end

    writeVideo(v,f)
    close(v)

我在pause之前尝试过getframe,但错误几乎每次都会发生。有人知道如何避免这种情况吗?

1 个答案:

答案 0 :(得分:0)

试试这个结构

v = VideoWriter('namefile.avi','Uncompressed AVI');
v.FrameRate = 6;
open(v);

startdate=1;
enddate=10;

fig=figure;
set(fig, 'position',[1 1 750 525])  

for s=startdate:enddate  

%your plotting code like
           %Z = randn(3);
           %surf(Z);

       currFrame = getframe(gcf);
       writeVideo(v,currFrame);
end

close(v);