Traditional Culture Encyclopedia - Weather inquiry - How to draw dynamic diagram with matlab?

How to draw dynamic diagram with matlab?

1. First, the code here is as follows:

x =-8:0.5:8;

[XX,YY]= mesh grid(x);

r=sqrt(XX。 ^2+YY.^2)+eps;

Z=sin(r)。 /r;

surf(Z);

Generate static surf diagram, and generate XX and YY with meshgrid.

2. Enter theAxes = axis below.

As you can see on the right, axes = [0 0,40,0,40, -0.5, 1], which is generated by the surf function. Because surf(XX, YY, z) is not used in the above picture, the coordinate range is different, but whatever the coordinate range is, it is first taken out and put in a variable for later use.

3、mat = movie in(20); Save the fmat as a movie in the structure, where 20 means that the animation has 20 frames.

4. Enter:

For j =1:20;

surf(sin(2*pi*j/20)*Z,Z)

axis

fmat(:,j)= get frame;

end

Here is to draw the image of each frame separately. Here our surf is drawn into 20 parts, and the coordinate axes are unified into the previously saved coordinate axes, and the structure of moviein fmat is taken as getframe, as shown in the figure.

5. Movies (fmat,10); That is, the animation is played 10 times.

6. The complete code is as follows:

x =-8:0.5:8;

[XX,YY]= mesh grid(x);

r=sqrt(XX。 ^2+YY.^2)+eps;

Z=sin(r)。 /r;

surf(Z);

Axis = axis;

fmat = movie in(20);

For j =1:20;

surf(sin(2*pi*j/20)*Z,Z)

axis

fmat(:,j)= get frame;

end

Movie (fmat, 10)

Complete the renderings.