Matlab 的动态曲线绘图

Line Animations

动态曲线的绘制
 

This example shows how to create an animation of two growing lines. The animatedline function helps you to optimize line animations. It allows you to add new points to a line without redefining existing points.

接下的例子将展示如何生成有关两根动态的曲线动画。

1、使用了animateline 函数帮助我们生成动态曲线。

2、该例子可以使我们在不用修改原有的数据基础上添加新的数据。

Contents

内容
  • Create Lines and Add Points
  • 生成曲线和添加点
  • Query Points of Line
  • 线段上点队列的生成

Create Lines and Add Points

Create two animated lines of different colors. Then, add points to the lines in a loop. Set the axis limits before the loop so that to avoid recalculating the limits each time through the loop. Use a docid:matlab_ref.f56-719157 or drawnow limitrate command to display the updates on the screen after adding the new points.

生成两条不同颜色的曲线。在这之后,将点的运动添加至线段的循环当中。为了避免在循环中重复计算运算还有展示区间需要先设置图像的大小。

添加新的点后可以使用drawnow limitrate 命令展示数据的更新。

a1 = animatedline('Color',[0 .7 .7]);
a2 = animatedline('Color',[0 .5 .5]);%区分颜色'Color',[0 .7 .7]);
a2 = animatedline('Color',[0 .5 .5]);%区分颜色
axis([0 20 -1 1])%设置图像区间,由图可见0-20位横坐标,-1-1为纵坐标
x = linspace(0,20,10000);%x的区间设定%设置图像区间,由图可见0-20位横坐标,-1-1为纵坐标
x = linspace(0,20,10000);%x的区间设定
%y = linspace(x1,x2,n) generates n points. The spacing between the points is (x2-x1)/(n-1).X点的步进
for k = 1:length(x);
    % first line
    xk = x(k);%更新x坐标
    ysin = sin(xk);
    addpoints(a1,xk,ysin);%点的添加

    % second line
    ycos = cos(xk);
    addpoints(a2,xk,ycos);

    % update screen
    drawnow limitrate %命令
end

Matlab 的动态曲线绘图_第1张图片

The animation shows two lines that grow as they accumulate data.

Query Points of Line

Query the points of the first animated line.

[x,y] = getpoints(a1);

x and y are vectors that contain the values defining the points of the sine wave.

 

你可能感兴趣的:(matlab,动画)