Error using getframe.

Hi, I am trying to program an AVI on a crank-slider mechanism, but it keeps on showing up this error:
"Error using getframe (line 53)"
"A valid figure or axes handle must be specified"
"Error in Animation (line 33)"
"F=getframe(1);"
I am really new to matlab, so I can't seem to resolve this error.
w = 1.25;
Ampl = 10;
t = [0:1/30:10];
Px = Ampl*cos(w*t);
Py = Ampl*sin(w*t);
AVI = 1;
M_Movie = 0;
if AVI==1
Rotation_Movie = VideoWriter('Rotation_Movie.avi');
open(Rotation_Movie);
end;
for k = 1:length(t);
plot(Px,Py);
hold on;
plot(Px(k),Py(k),'r.','MarkerSize',25);
if k > 5;
plot(Px(k-1),Py(k-1),'r.','MarkerSize',20);
plot(Px(k-2),Py(k-2),'r.','MarkerSize',15);
plot(Px(k-3),Py(k-3),'r.','MarkerSize',10);
plot(Px(k-4),Py(k-4),'r.','MarkerSize',5);
plot(Px(k-5),Py(k-5),'r.','MarkerSize',1);
end;
hold off;
F=getframe(1);
if(AVI);
writeVideo(Rotation_Movie,F);
elseif (M_Movie)
E_movie(k)=F;
end;
end;
if(AVI);
close(Rotation_Movie);
end;

回答(1 个)

Hariharan - rather than using 1 as an input to getframe, why not try using gcf to get the handle to the current figure (which may not be '1' for whatever reason)? Replace your above with
F=getframe(gcf);

3 个评论

I suspect gca would be better than gcf
Yes, you are right. The error resolved, but I made it wheel spin round and round. How to I get it to go back and forth like a crank-slider would do? Thank you.
Hariharan - back and forth from which point? Do you mean to say that if the Marker reaches a certain angle (relative to the origin) of the circle then it should change direction and so bound back and forth between two points?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Animation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by