Matlab 的动态曲线绘图

该博客介绍了如何在Matlab中创建动态曲线动画,通过使用`animatedline`函数逐步添加点来实现两条不同颜色曲线的增长,同时展示了如何设置轴限和实时更新屏幕。此外,还演示了如何查询动画线条上的点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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]);%区分颜色'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

CreateLineAnimationOfStreamingDataExample_01.png

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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值