简体   繁体   中英

How to plot moving figure in matlab

How I can make an animation like Fig. 3.2: in the following link

clc;clear all;
x=[1 1.2 1.4 2 3 4 5 7 9 10];
y=[2.8 7.6 10.9 12.3 15.0 21 12.3 14.5 42.4 47.7  ];
plot(x,y)

As discussed here , there are multiple ways to Animate Plots. You can create animated sequences with MATLAB® graphics in three different ways:

  1. Save a number of different pictures and play them back as a movie.

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

  3. Redefine the XData, YData, ZData, and/or CData plot object properties, optionally linking them to data sources (workspace variables) and updating the properties via calls to refreshdata.

Check out the following example:

c = -pi:.04:pi;
cx = cos(c);
cy = -sin(c);
figure('color','white');
axis off, axis equal
line(cx, cy, 'color', [.4 .4 .8],'LineWidth',3);
title('See Pythagoras run!','Color',[.6 0 0])
hold on
x = [-1 0 1 -1];
y =   [0 0 0 0];
ht = area(x,y,'facecolor',[.6 0 0]);
for j = 1:length(c)
    x(2) = cx(j);
    y(2) = cy(j);
    set(ht,'XData',x)
    set(ht,'YData',y)
    drawnow
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM