1. 程式人生 > >Matlab 的動態曲線繪圖

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

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]);%區分顏色
axis([0 20 -1 1])%設定影象區間,由圖可見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

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.