在Matlab上对线进行动画处理 [英] Animate a line on matlab

查看:111
本文介绍了在Matlab上对线进行动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在matlab上制作一个自我更新的情节动画.例如,弦在两端之间振动.我在文档中找到的所有基本动画功能都可以完成相同的工作,主要是对不断发展的绘图进行动画处理.即函数保持不变,但绘制的点数随时间增加(或减少).例如,以下脚本:

I would like to animate a self updating plot on matlab. For example a string vibrating between two ends. All the basic animate functions I have found in the documentation accomplish the same thing, mainly to animate an evolving plot. I.e the function remains the same but the number of points plotted increases (or decreases) in time. For example this script:

h = animatedline;
axis([0,4*pi,-1,1])

x = linspace(0,4*pi,1000);
y = sin(x);
for k = 1:length(x)
    addpoints(h,x(k),y(k));
    drawnow
end

跟踪正弦函数,就像用一只看不见的手在画它一样.我想做的是对整个函数进行动画处理,但是要使用变化的参数,例如相位或幅度.我尝试使用以下内容进行修改:

traces a sine function as if an invisible hand was drawing it. What I would like to do is animate the entire function but with a varying parameter, like the phase or amplitude. I tried to modify using the following:

x = linspace(0,4*pi,1000);

;
axis([0,4*pi,-1,1])

for k = 1:10
    h = animatedline(x,sin(k*x))
    drawnow
end

这有点接近我所需要的,但是功能是逐步添加的,而不是被替换的.这样一来,总共绘制了10个函数,而不是动画.

This is sort of close to what I need but the functions are progressively appended, not replaced. This results in a total of 10 functions being plotted instead of an animation.

有人知道我需要做什么吗?如果可以的话,如何完成?

Does anyone understand what I need to do? If so how can this be accomplished?

推荐答案

这是怎么回事:

h = animatedline;
axis([0,4*pi,-1,1]);

x = linspace(0,4*pi,1000);

for k = 1:0.01:10
    y = sin(k*x);
    clearpoints(h);        
    addpoints(h,x,y);
    drawnow 
end

这篇关于在Matlab上对线进行动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆