Error using getframe.

조회 수: 10 (최근 30일)
HARIHARAN HEMARAJAN
HARIHARAN HEMARAJAN 2015년 10월 30일
댓글: Geoff Hayes 2015년 10월 31일
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개)

Geoff Hayes
Geoff Hayes 2015년 10월 30일
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
HARIHARAN HEMARAJAN
HARIHARAN HEMARAJAN 2015년 10월 31일
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.
Geoff Hayes
Geoff Hayes 2015년 10월 31일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by