Error using VideoWriter/writeVideo (line 344) Frame must be 434 by 343
    25 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    saravanakumar D
 el 27 de Feb. de 2017
  
    
    
    
    
    Respondida: venus
 el 22 de Jul. de 2019
            I getting error: Error using VideoWriter/writeVideo (line 344) Frame must be 434 by 343
Error in movie_trial5 (line 22) writeVideo(v,getframe(gca))
Here is my code:
nframes=50;
Frames=moviein(nframes);
x1=linspace(0,L,1000);
x2=linspace(L,2*L,1000);
figure
v = VideoWriter('E:\newfile.avi');
open(v)
for t=1:nframes
  y1=sin(x1)*cos(20*t);
  y2=sin(2*L-x2)*cos(20*t);
  plot (x1,y1,x2,y2,'Linewidth',3)
  writeVideo(v,getframe(gca))
end
close(gca)
close(v)
1 comentario
  Geoff Hayes
      
      
 el 27 de Feb. de 2017
				Perhaps the frame size is changing on an iteration of your for loop which leads to the error. Try doing
 for t=1:nframes
   y1=sin(x1)*cos(20*t);
   y2=sin(2*L-x2)*cos(20*t);
   myFrame = getframe(gca);
   size(myFrame.cdata)
   writeVideo(v,myFrame)
 end
Does the size of the frame ever change?
Respuesta aceptada
  Walter Roberson
      
      
 el 27 de Feb. de 2017
        nframes=50;
Frames=moviein(nframes);
x1=linspace(0,L,1000);
x2=linspace(L,2*L,1000);
figure
v = VideoWriter('E:\newfile.avi');
open(v)
ax = gca();
for t=1:nframes
  y1=sin(x1)*cos(20*t);
  y2=sin(2*L-x2)*cos(20*t);
    if t == 1
      h = plot(ax, x1, y1, x2, y2, 'Linewidth',3);
      set(ax, 'XLimMode', 'manual', 'YLimMode', 'manual');
    else
      set(h(1), 'YData', y1);
      set(h(2), 'YData', y2);
    end
    drawnow();
    writeVideo(v,getframe(ax))
  end
  close(gca)
  close(v)
Besides being more efficient, this avoids the chance that the frame will change size.
0 comentarios
Más respuestas (1)
  venus
 el 22 de Jul. de 2019
        A simple solution is to keep the first figure with its size (with using hold on) and plot all the data in it.
nframes=50;
Frames=moviein(nframes);
x1=linspace(0,L,1000);
x2=linspace(L,2*L,1000);
myfig = figure();
hold on
v = VideoWriter('E:\newfile.avi');
open(v)
for t=1:nframes
  y1=sin(x1)*cos(20*t);
  y2=sin(2*L-x2)*cos(20*t);
  plot (x1,y1,x2,y2,'Linewidth',3)
  writeVideo(v,getframe(gca))
  clf(myfig);
end
close(gca)
close(v)
0 comentarios
Ver también
Categorías
				Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



