0

VideoWriter我的代码使用该函数在 for 循环中生成 10 个视频。我知道如何预分配数组,但我不确定如何对 VideoWriter 文件进行预分配。下面代码中的 writerObj 文件应该是预先分配的。

for i=1:10
 
     images  = cell(28,1);
    writerObj(i) = VideoWriter(sprintf('bc_e2_ld_e5_time_history1/%d.avi',i));
    writerObj(i).FrameRate = 1;   % create the video writer with 1 fps
    secsPerImage = ones(1,28);  % set the seconds per image
    open(writerObj(i));   % open the video writer
    
 %-----------------------------Save images for making videos ---------------   
    
     for j=1:28
        h=figure('visible','off');    
        p = pcolor(intrpVMStress1(:,:,j));
        p.EdgeColor='none';
        set(gca,'visible','off')
        colormap('jet');
%       colorbar;
        axis equal;
        title 'Von Mises Stress';
        saveas(h,sprintf('bc_e2_ld_e5_time_history1/FIG%d.jpg',j));  % save the images
        images{j}=imread(sprintf('bc_e2_ld_e5_time_history1/FIG%d.jpg',j)); % load the images
     end 
     
%-----------------------------convert the image to a frame ---------------    
      for u=1:length(images)
            % convert the image to a frame
          frame = im2frame(images{u});
                 for v=1:secsPerImage(u) 
                     writeVideo(writerObj(i), frame);
                 end
      end
 close(writerObj(i)); 
    
end
4

0 回答 0