필터 지우기
필터 지우기

Code's improvement (plots animation)

조회 수: 1 (최근 30일)
Julián Francisco
Julián Francisco 2011년 6월 3일
Hi. My intention is creating an animated plot which will represent the trajectory of a body in the space. I have written this code for it. My problem is more simple that it appears. I want to see the movie (the animated plot stored) in the active figure window but I can not. When I maximize the window, I realize it is empty i.e. the movie is not contained.
t = 0:pi/50:10*pi;
x = sin(t);
y = cos(t);
z = t;
xmin = min(x);
ymin = min(y);
zmin = min(z);
xmax = max(x);
ymax = max(y);
zmax = max(z);
fh = figure;
ah = axes('Parent',fh);
N = 101;
for i = uint8(1):uint8(N+1)
delta = (10*pi)/N;
b = delta*(double(i-1));
t = 0:0.01:b;
plot3(ah,sin(t),cos(t),t);
set(ah, 'XLim', [xmin xmax],'YLim', [ymin ymax],'Zlim',[zmin zmax]);
axis square;
pause(0.008);
M(i) = getframe(gcf);
end
cla;
movie(fh,M,1);

채택된 답변

Jonas Reber
Jonas Reber 2011년 6월 3일
the problem is that getframe as used by you gets the current figure as it is. If you maximize the window and "record" the movie maximized, you will get a maximized movie.
you could change getframe(gcf) to getframe(gca) to only retrieve the axis. but this still takes the axes as it is when recording.
  댓글 수: 5
Jonas Reber
Jonas Reber 2011년 6월 4일
you have to think of the function "getframe" as a "printscreen" function which takes an image of your screen (a selected rectangle - notice that you can even define a rectangle with getframe) as you see it at that very moment (that's why it doesn't work when the screensaver is on).
if you now let getframe get a picture of your figure it is basically the same as if you would manually do such a printscreen of your figure window. what happens if you do a printscreen is that you get an image of the size of your screen resolution. getframe basically gets you an image of the size of your handle (axes, figure, ...).
If you then play back this image in a different (bigger) window its resolution hasn't change and therefore appears smaller. the movie command does - to my knowledge - not scale the images and therefore you end up with a smaller movie in a maximized figure.
what you could do is to export your movie to an avi (movie2avi) and play back the movie in your favourite movie player...
Julián Francisco
Julián Francisco 2011년 6월 8일
@Jonas Reber: Ok, Jonas. I have just understood the working of getframe and movie functions. Thanks for your remarks. Cheers.

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

추가 답변 (0개)

카테고리

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