MATLAB dynamic drawing

(1) Dynamic drawing of function image        

        The dynamic drawing of MATLAB can show the process of drawing, and the following four functions are used:

% animatedline creates an animated timeline;

% addpoints Add points to the timeline of the animation;

% getpoints Get point data information;

% clearpoints clear points, can be used at the end, the point is cleared.

        The following code will implement the drawing process of the sin function, the specific code is as follows:
 

x=-4*pi:0.1:4*pi;
y=sin(x);

h1=animatedline('color','b','marker','o');
% axis([-4*pi 4*pi -1.1 1.1]);
for i=1:(length(x)/2)
   addpoints(h1,x(i),y(i))
   drawnow;     %立刻绘图
end
%显示25个点的作图过程
h2=animatedline(x(length(x)/2),y(length(x)/2),'color','r','marker','*','maximumnumpoints',25);
for i=(length(x)/2):length(x)
   addpoints(h2,x(i),y(i))
   drawnow;
end

(2) Animation display of the sphere

        The following code will animate a spherical surface, mainly through the movie(a,b) function, where:

① The parameter a is the object to play the animation;

② Parameter b is the number of times to play the function.

[X,Y,Z]=sphere;             %创建20*20球面
surf(X,Y,Z)                 
axis([-3,3,-3,3,-1,1])      %调整坐标范围
axis off                    %关闭坐标系
shading interp              %利用插值颜色渲染
colormap(cool)               %将颜色值cool设置为当前颜色
M=moviein(20);              %建立一个20列大矩阵
for i=1:20
    view(-37.5+24*(i-1),30) %改变视点
    M(:,i)=getframe         %图形保存到矩阵
end
movie(M,3)                  %播放三次

Guess you like

Origin blog.csdn.net/weixin_58351753/article/details/127619465