在Matlab动画制作流程 [英] Animation process in Matlab

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

问题描述

我只是在学习如何使用Matlab的。问题是简单的动画2D图。

I am just learning how to use Matlab. The problem is animating simple 2D plots. In trying to animate a line from (0,0) to (0, 10) connecting them in an animation I have this so far:

x = 0;
p = plot(x, y, 'o', 'EraseMode', 'none'); % p is the handle, for later manipulations
axis equal
for k = 0:1:10 % the idea here is to have k go from 0 to 10 and set y to that value
    y = k;
    set(p,'XData', x, 'YData', y) % then this adds another point based on that new y 
drawnow
end

的问题是,当该运行时,是它仅绘制的第一点。任何帮助AP preciated。

The problem is, when this is run, is that it only plots the first point. Any help appreciated.

推荐答案

您应该划一条线由两个点定义,然后在每次迭代更新的第二个点的y值:

You should draw a line define by two points, and then at each iteration update the y value of the second point:

h = plot([0 0],[0 0]); %// draw line initially
axis([-1 1 0 10]) %// freeze axis to see how the line grows
for k = 0:.1:10
    set(h,'YData',[0 k]) %// update second y value
    drawnow
end

这篇关于在Matlab动画制作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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