Code's improvement (plots animation)
2 views (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
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
on 4 Jun 2011
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...
More Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!