This action might not be possible to undo. Are you sure you want to continue?

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

Animation :: Creating Specialized Plots ...

Graphics

Animation

Provide feedback about this page

www.kxcad.net Home> CAE Software Index> MATLAB Index>

Your Ad Here

On this page ...

Ways to Aillmate Plots Movies

Example - Visualizing an FFT as a Movie Erase Modes

Ways to Animate Plots

You can create animated sequences with MATLAB in two different ways:

• Save a nwnber of different pictures and then play them back as a movie.

• Continually erase and then redraw the objects on the screen, making incremental changes with each redraw.

Movies are better suited to situations where each frame is fairly complex and cannot be redrawn rapidly. You create each movie frame in advance so the original drawing time is not important during playback, which is just a matter ofblitting the frame to the screen A movie is not rendered in real time; it is simply a playback of previously rendered frames.

The second technique, drawing, erasing, and then redrawing, makes use of different drawing modes supported by MATLAB. These modes allow faster redrawing at the expense of some rendering accuracy, so you must consider which mode to select.

This section provides an example of each technique. To see more sophisticated demonstrations of these features, type demo at the MATLAB prompt and explore the animation demonstrations.

~ I Back to Top

Movies

You can save any sequence of graphs and then play the sequence back in a short movie. There are two steps to this process:

• Use getframe to generate each movie frame. Be sure that your computer is not in screen saver mode when getframe is called, and in the event that you are using several virtual desktops, that the one on which MATLAB is running is visible on your monitor.

• Use movie to nm the movie a specified nwnber of times at the specified rate.

Typically, you use getframe in a for loop to assemble the array ofmovie frames. getframe returns a structure having the following fields:

• cdata - Image data in a uintS matrix. The matrix has dimensions ofheight-by-width on indexedcolor systems and height-by-width-by-3 on truecolor systems.

• colormap - The colormap in an n-by-3 matrix, where n is the nwnber of colors. On truecolor systems, the colormap field is empty.

See image for more information on images.

~ I Back to Top

kxcad.netjcae_MATLAB/ .. ./flO-1460.html

1/5

10/10/2010

Animation :: Creating Specialized Plots ...

Example - Visualizing an FFT as a Movie

This example illustrates the use of movies to visualize the quantity fft (eye (n) ) , whch is a complex n-by-n matrix whose elements are various powers of the nth root ofunity, exp (i *2*pi/n).

Creating the Movie

Create the movie in a for loop calling getframe to capture the graph Since the plot command resets the axes properties, call axis equal within the loop before getframe.

for k = 1:16 plot(fft(eye(k+16))) axis equal

M(k) = getframe;

end

Running the Movie

After generating the movie, you can play it back any number of times. To play it back 30 times, type

movie (M, 30)

You can readily generate and smoothly play back movies with a few dozen frames on most computers. Longer movies require large amounts of primary memory or a very effective virtual memory system

Movies that Include the Entire Figure

If you want to capture the contents of the entire figure window (for example, to include GUI components in the movie), specify the figure's handle as an argument to the getframe command. For example, suppose you want to add a slider to indicate the value ofk in the previous example.

h = uicontrol('style', 'slider', 'position', ...

[10 50 20 300]"Min',1,'Max',16,'Value',1)

for k = 1:16 plot(fft(eye(k+16))) axis equal

set (h, 'Value' , k)

M(k) = getframe(gcf);

end

In this example, the movie frame contains the entire figure. To play so that it looks like the original figure, make the playback axes fill the figure window.

clf

axes('Position',[O 0 11]) movie (M, 30)

~ I Back to Top

Erase Modes

You can select the method MA TLAB uses to redraw graphics objects. One event that causes MA TLAB to redraw an object is changing the properties of that object. You can take advantage of this behavior to create animated sequences. A typical scenario is to draw a graphics object, then change its position by respecifying the X-, Y,- and z-coordinate data by a small amount with each pass through a loop.

You can create different effects by selecting different erase modes. This section illustrates how to use the three modes that are useful for dynamic redrawing:

• none - MATLAB does not erase the objects when it is moved.

• background - MATLAB erases the object by redrawing it in the background color. This mode erases the object and anything below it (such as grid lines).

• xor - This mode erases only the object and is usually used for animation,

All three modes are faster (albeit less accurate) than the normal mode used by MA TLAB.

kxcad.netjcae_MATLAB/ .. ./flO-1460.html

2/5

10/10/2010

Animation :: Creating Specialized Plots ...

Example - Animating with Erase Modes

It is often interesting and informative to see 3-D trajectories develop in time. This example involves chaotic motion described by a nonlinear differential equation known as the Lorenz strange attractor. It can be written

. h ~ r!::r- Ay' ill t e rorm dt- .

with a vector _ vaned fimction y(t) and a matrix A that depends upon y. A(y) -l ~~) - ~o y ~~ j

The solution orbits about two different attractive points without settling into a steady orbit about either. This example approximates the solution with the simplest possible numerical method - Euler's method with fixed step size. The result is not very accurate, but it has the same qualitative behavior as other methods.

A [-8/3 0 0; 0 -10 10; 0 28 -1 i.

y [35 -10 -7] ';

h 0.01;

p p1ot3(y(1),y(2),y(3),'.',

'EraseMode', 'none', 'MarkerSize',5); % Set EraseMode to none axis([O 50 -25 25 -25 25])

hold on

for i=1:4000

A(1,3) y(2);

A(3,1) = -y(2); ydot = A*y;

Y = Y + h*ydot;

% Change coordinates

set (p, 'XData', y (1), 'YData', y (2), 'ZData', y (3)) drawnow

end

The p1ot3 statement sets EraseMode to none, indicating that the points already plotted should not be erased when the plot is redrawn. In addition, the handle of the plot object is saved. Within the for loop, a set statement references the plot object and changes its internally stored coordinates for the new location. While this rranual cannot show the dynamically evolving output, this picture shows a snapshot.

kxcad.netjcae_MATLAB/ .. ./flO-1460.html

3/5

10/10/2010

Animation :: Creating Specialized Plots ...

,"",

. >.

',', .

... ,,',

,-

" • ':. ~ ~-. • -, I

.: .. l' ";' . :~. -~ .• : •. ' ..

:: .. .'. .. ~"'.' .. ',. ': ;_ .. '.' .," ~ ,

~ ••••• ~- .: :_',_ ;-._'~'-::-~-.:':' :~ I I

--'-'-"'-~:'_;,I' . ~.? :_,'_:

-- - .. .' .. :<_,:.-~~:-.~ ~~- .~~_·I :.: .

, ,-

,', .

~ •• 1'"

.' .', ":'.' .. ~, .

. ~ .~. .

.. I ~ I ..

-.-",.- r:

. -' .

20

.v-.

.... ",' L·. . .:. ~ .. -. -, ~

I .. I'" :'~ '~I ';. ..

.; ~ " ".: ...

~ .. "

_-

.. -', ...

oJ' ••

" ... ~ .

50

"

30

Note that, as fur as MA TLAB is concerned, the graph created by this example contains only one dot. What you see on the screen are renmants of previous plots that MATLAB has been instructed not to erase, The only way to print this graph from MA TLAB is with a screen capture,

Background Erase Mode. To see the effect of Erase Mode background, add these statements to the preVIOUS program

p = plot3(y(1),y(2),y(3),'square',

'EraseMode', 'background', 'MarkerSize',10, ... 'MarkerEdgeColor' , [1 .7 .7],' MarkerFaceColor ' , [1 .7 .7]);

for i=1:4000

A(1,3) y(2);

A(3,1) = -y(2); ydot = A*y;

Y = Y + h*ydot;

set (p, 'XData', y (1), 'YData', y (2), 'ZData', y (3)) drawnow

end

hold off

Since hold is still on, this code erases the previously created graph by setting the EraseMode property to bac kground and changing the marker to a ''pink eraser" (a square marker colored pink).

Xor Erase Mode. If you change the EraseMode of the first plot3 statement from none to x o r , you will see a moving dot (Marker' . ,) only. Xor mode is used to create animations where you do not want to leave renmants of previous graphics on the screen However, you should not rely on Xor mode to work properly in all situations. Some platforms and graphics subsystems do not support it and where it does work, performance can be much slower compared to other erase modes or animation methods.

kxcad.netjcae_MATLAB/ .. ./flO-1460.html

4/5

10/10/2010 Additional Examples

The MATLAB demo lorenz provides a more accurate numerical approximation and a more elaborate display of the Lorenz strange attractor example. Other MATLAB demos illustrate anirmtion techniques.

Animation :: Creating Specialized Plots ...

~ I Back to Top

Provide feedback about this page Displaying Bit-Mapped Images III

I±I Interactive Plotting

© 1984-2007 The MathWorks, Inc .. Terms of Use . Patents . Trademarks· Acknowledgments Your Ad Here

kxcad.netjcae_MATLAB/ .. ./flO-1460.html

5/5

- Public Service Rules
- Unit 49 Installing and Commissioning Engineering Equipment
- Monte Carlo Method
- Strain Gauge - Wikipedia, The Free Encyclopedia
- PMP Mock Exams
- NSRL _ About Soy_ Soybean P..
- NSRL _ About Soy_ Soybean P..
- Vegetable Oil Extraction Process of Progress - Agriculture and Forestry Science Class Papers
- soyabeans oil production chart
- Technical Paper #40
- Auto
- Auto

- On Writing
- The Shell Collector
- I Am Having So Much Fun Here Without You
- The Rosie Project
- The Blazing World
- Hyperbole and a Half
- Quiet Dell
- After Visiting Friends
- Missing
- Birds in Fall
- The Great Bridge
- Who Owns the Future?
- The Wife
- On Looking
- Catch-22
- A Farewell to Arms
- Goat Song
- Birth of the Cool
- Girl Reading
- Galveston
- Telex from Cuba
- Rin Tin Tin
- The White Tiger
- The Serialist
- No One Belongs Here More Than You
- Love Today
- Sail of Stone
- All My Puny Sorrows
- Fourth of July Creek
- The Walls Around Us

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd