Code's improvement (plots animation)

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);

 Accepted Answer

Jonas Reber
Jonas Reber on 3 Jun 2011
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 Comments

@Jonas Reber: Thank you for your suggestion. However, it does not fix the problem because, after changing getframe(gcf) to getframe(gca), now there are two overlapped axes in the same window.
thats probably because you play back the movie in a new axis in your old figure (fh) where the axis from which you recorded (ah) is still in.
you could just play back the movie in this axes by changing it to:
movie(ah,M,1);
or you open a new figure and play it there:
f = figure;
movie(f,M,1);
@Jonas Reber: If I use movie(ah,M,1) it looks like to work but I do not undertand why the movie disappears when I maximize the figure window.
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...
@Jonas Reber: Ok, Jonas. I have just understood the working of getframe and movie functions. Thanks for your remarks. Cheers.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!