从数据MATLAB动画线图 [英] MATLAB animate line plots from data

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

问题描述

我有30个实验性试验,我登录一个DAQ,我到MATLAB使用xlsread阅读这些。

I have 30 experimental trials that I logged on a DAQ and I read these in to MATLAB using xlsread.

我有一个情节,现在我在这里上显示一个数字的所有30次试验。

I have a plot now where I show all 30 trials on one figure.

我想要做的就是创建一个电影它显示他们绘制一个接一个。

真的,我一共有60线图(30输入和30输出),所以这将是巨大的,如果我能证明的输入和输出为一体,那么接下来,等等。

Really I have a total of 60 line plots (30 inputs and 30 outputs), so it would be great if I could show the input and output for one, then the next, etc.

现在我的code是类似这样的:

Right now my code is similar to this:

In_1 = xlsread(filename.xls, #1);
In_2 = xlsread(filename.xls, #2);
...

Out_1 = xlsread(filename.xls, #1);
Out_2 = xlsread(filename.xls, #2);
...
plot(t, In_1,'r')
plot(t, Out_1)
plot(t, In_2,'r')
plot(t, Out_2)
...

我见过很多使用的getFrame和电影的例子。这并不能帮助我,因为我数据绘制。不被在一时间间隔进行评价的功能。我试图绘制数据的30次试验。

I've seen plenty of examples using getframe and movie. This does not help me, because I am plotting DATA. Not a function that is evaluated over a time interval. I am trying to plot 30 trials of data.

推荐答案

使用 AVIFILE 来创建一个AVI文件,然后的 ADDFRAME的 来捕获每个绘制的图形,你的情节,并将其转换为图文框。我也冒昧添加 次要情节 以保持双方地块在同一个人物,重写你的code为一个循环。

Use avifile to create an AVI file and then addframe to capture each plotted graph you plot and convert it to a frame. I've also taken the liberty to add subplots to keep both plots in the same figure, and rewrite your code into a loop.

下面是我(修订版)建议的解决方案:

Here's my (revised) suggested solution:

aviobj = avifile('output.avi');                     %# Create an AVI file
hh = figure;
for i = 1:30
    figure(hh)                                      %# Reuse the figure
    subplot(2, 1, 1)
    eval(['plot(t, In_', num2str(i), ', ''r'')']);  %# Plot i-th input
    %# axis([ something ]);
    subplot(2, 1, 2)
    eval(['plot(t, Out_', num2str(i), ', ''r'')']); %# Plot i-th output
    %# axis([ something ]);
    aviobj = addframe(aviobj, getframe(hh));        %# Convert to a frame
end
aviobj = close(aviobj);                             %# Close the AVI file

您可以使用 AVIFILE 选项拨弄控制生成的视频的质量。

You can fiddle with the avifile options to control the quality of the generated video.

阿洛斯注意,每个设置x,并根据绘制的值y轴上。如果你想保留动画平稳,你必须强制轴为​​每个图形保持不变,每次打印后,使用的 命令。

Alos note that each plot sets the x and y axes according to the plotted values. If you want to keep the animation "smooth", you have to force the axes to remain constant for each graph, after every plot, using the axis command.

这篇关于从数据MATLAB动画线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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