Created
November 1, 2012 21:41
-
-
Save dracid/3996785 to your computer and use it in GitHub Desktop.
Saving sequence of plots into animated AVI file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ====================================== | |
% File: ani2avi | |
% Date: 1.Nov.2012 | |
% Purpose: Saving a sequence of plots into avi file | |
% | |
% Author: Giorgi Maghlakelidze | |
% ====================================== | |
clc; clear all; close all | |
% ===[ Example ] ======================= | |
t = 0:1/30:2*pi; % Time in seconds | |
sint = sin(t); % Sine as a function of time | |
% ====================================== | |
filename = 'movie.avi'; % Set movie filename | |
movie = avifile(filename,'FPS',30); % Create a avifile object called 'movie' with 30 fps | |
fig = figure; % Record the handle of figure | |
for i = 1:length(t) | |
plot(t, sint); % Plot the general path | |
hold on % Allow drawing of other objects | |
plot(t(i), sint(i), 'or') % Plot state of sin function at current time | |
hold off % This means the next plot replace current one | |
axis([t(1) t(end) -1 1]); % Fix the boundaries of view, so that it doesn't change from graph to graph | |
F = getframe(fig); % Record current drawing, use 'getframe(gca)' to record only central area | |
movie = addframe(movie,F); % Add saved frame to the movie | |
end | |
movie = close(movie) % Once all the frames are recorded, finalize the file and print info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment