Michael Ward
Michael Ward

Reputation: 213

Step through movie frame by frame in matlab

I wish to plot a figure that changes over time in matlab. I then wish to be able to step through the plots in time-steps frame by frame. How can I achieve this? I have created a movie but there seems to be no way to step through it in an easy fashion. I have seen this somewhere before so I know that there is a solution.

Upvotes: 3

Views: 2024

Answers (1)

benpro
benpro

Reputation: 4425

If your movie was created with "getframe", you can use code like the following:

This sets up an example movie:

Z = peaks; surf(Z); 
axis tight
set(gca,'nextplot','replacechildren');
% Record the movie
for j = 1:20 
    surf(sin(2*pi*j/20)*Z,Z)
    F(j) = getframe;
end
% Play the movie
figure(1);clf;
movie(F)

This examines each frame, one at a time:

for j=1:20
    [X,map] = frame2im(F(j));
    figure(2);clf;
    image(X);
    pause; 
end

Pressing the space bar will release the "pause" so that you can examine each frame independently.

Upvotes: 2

Related Questions