movie
Captures an image of a figure.
Syntax
movie(f)
movie(f, n)
movie(f, n, fps)
movie(h, ...)
Inputs
- f
- A vector of frames to display. Each frame should be a structure which contains the field 'cdata'. Frames can be created by using the getframe command.
- n
- If n is a scalar then it sets the number of times the movie will be diplayed. If n is a vector then the first element of n sets the number of times the movie will be displayed and the rest of the elements define the indices of the frames to be displayed. In case the number of repetitions is < 0 then the movie playback will alternate between forward and backward order.
- fps
- Frames to display per second.
- h
- Figure handle.
Outputs
- f
- A struct which contains the field 'cdata'. The value of 'cdata' is an MxNx3 matrix - the r,g,b values of each pixel of the captured image.
Example
t = 0:0.1:20;
x = sin(t);
y = cos(t);
num_frames = length(t);
figure();
l1 = plot(t(1),x(1),'bo');
hold on
l2 = plot(t(1),y(1),'ro');
axis([0 max(t) -1 1]);
drawnow;
for k = 1:num_frames
set(l1, {'xdata', 'ydata'}, {t(k), x(k)});
set(l2, {'xdata', 'ydata'}, {t(k), y(k)});
f(k) = getframe;
end
% play movie in a new figure
figure;
fps = 20;
% 20 frames per second - show 1 time
movie(f, 1, fps)
figure;
fps = 10;
% 10 frames per second - show 2 times (one forward, one backward), show only certain frames
movie(f, [-2 10:10:200], fps)