leftimage for poohprod.ru

Simple Animation in Matlab



If we have some data representing a system or a function at several time intervals, we may want to take advantage of Matlab’s simple animation capabilities. We're going to expose the basic method or algorithm for animations.


In this example we’re going to work with just three special instructions.

The idea is to store every figure as a frame of the ‘movie’, with each frame stored as a column vector of a matrix, an then play all the frames on the screen.

moviein(nr_frames): we initialize the matrix that will keep the frames, with the number of frames to be generated.

getframe: with this instruction we keep the information of a given figure and ‘load’ a temporary matrix with information.

movie(matrix, times, FPS): this is used to play the movie after its generation. Parameter ‘matrix’ is the saved data, ‘times’ the number of times that the movie will be played back, and ‘FPS’ means ‘frames per second’ (the default is 12).

Let’s try this simple animation example:

% Define number of frames
nr_fr = 10;
% Initialize matrix using 'moviein'
frames = moviein(nr_fr);

% Generate frames with any plotting function.
% We use a cosine with variable frequency.

t = 0 : .01 : 6;
f = 1;

for i = 1 : nr_fr
f = f * 1.25; w = 2 * pi * f;
y = cos(w*t);
plot(t, y);
title(
'Recording movie...')
% Get every frame with 'getframe' and load the appropriate % matrix.
frames(:, i) = getframe;
end

% Save the matrix so that this movie can be loaded later
save frames

This is the first frame of the recording:

simple animation in Matlab

Now you can play back the movie:

% Play the movie once, 2 FPS.
title('Movie being played back...')
movie(frames, 1, 2)

This is the last frame of the animation:

Matlab: algorithm animations


Done!


From 'Simple Animation' to home

From 'Simple Animation' to 2D Menu

Top

Animation: comets

3D Animation



footer for simple animation page


























Related pages


matlab if multiple conditionsmatlab line widthdefine salvage valuequad in matlabcollatz sequencepi infinite seriescompute compound interestleast square fitting matlabhow to solve quadratic equations in matlabbernoulli distribution matlabc code for pascal trianglegauss jorden methodharmonic seriesmatlab loops examplesnumerical magic tricksresistor color code downloadspecial characters ascii valuesdouble integration in matlabunit impulse function matlabinterp1 matlabbinary to octal converter onlineprime factorization tutorialoctal to binary tablelagrange polynomial examplematlab matrix multiplicationprobability plot matlabconvert binary to decimal examplessolve simultaneous equations matlabgui in matlabif statement in matlab examplebisection method programdecay formula calculatorconversion of decimal to octalmatlab basic commandsbinary to grey codesalvage value and depreciationsimpson matlabmatlab buttonslinear algebra matlabgui example matlabfinding factorialpascal triangle codematlab plot3calculating angles between vectorspolyfit in matlabdecimal ascii tableboolean axiomsdelta diracaascii table copy pastedouble integral in matlabdifferential equation of rc circuitdecimal to binary conversion algorithmnodal analysis sample problemssample matlab programslaptop depreciationmatlab axis titlehow to convert double to int in matlabgauss distribution matlabbabylonian methodmatlab booksinfinite geometric series sum formulamod function matlabdemorgans lawsuiwait matlabhow to graph functions in matlabsine taylor seriesbisection method algorithm matlabbasic matlab tutorialinverse function matlabcurve fitting matlab codecompound interest calculator spreadsheetscrap value and salvage valuemaclaurin polynomial