【问题标题】:Time series animation in MatlabMatlab中的时间序列动画
【发布时间】:2019-03-16 09:11:09
【问题描述】:

我是在 Matlab 中处理时间序列的新手,并且正在努力实现这一目标。我在这 11 个位置有时间序列传热数据(超过 20 毫秒,步长为 1 微秒)(见下面的代码)。我不知道如何将它们放在一起以便能够在每个时间步生成绘图并在每个时间步使用 getframe 来制作动画。任何有关如何开始使用此功能的帮助将不胜感激。这是 11 个数据文件的链接,在 column1 上提供时间,在 column2 上提供热传递:https://drive.google.com/open?id=1oDAdapqvL-blecb7BOLzxpeiJBsqLd59

请随时建议在这种情况下可能更好的任何其他工具(matplotlib/plotly 等)。万分感谢!

close all
clear all

x1=399.5
x2=400.5


y0=0 
y1=4
y2=8
y3=12
y4=16
y5=20
y6=-4
y7=-8
y8=-12
y9=-16
y10=-20

%The gauge locations for the first row will be [x1,y1], [x1,y3], [x1,y5], [x1,y6], [x1,y8],
%[x1,y10]

%The gauge locations for the second row will be [x2,y0], [x2,y2], [x2,y4], [x2,y7],
%[x2,y9]

figure

plot(x1,y1,'r.', x1,y3,'r.', x1, y5, 'r.', x1, y6, 'r.', x1, y8, 'r.', x1, y10, 'r.')
hold
plot(x2,y0,'b.', x2,y2,'b.', x2, y4, 'b.', x2, y7, 'b.', x2, y9, 'b.')
axis([390 410 -30 30])

【问题讨论】:

标签: matlab animation time-series


【解决方案1】:

您可以在 Matlab 中使用 getFramewriteVideo 函数。我将针对一个非常一般的案例进行解释,然后您可以将其应用于您的案例。

假设我们有一个图,它在 for 循环内的每次迭代中更改它的数据(在求解 PDE 等时经常发生),并带有示例函数 solverIteration(编造...)。我们正在我们的域x 上绘制一个向量y

为了录制视频,我们必须执行以下操作:

video = VideoWriter('myVideo.avi'); %Create a video object
open(video); % Open video source - restricts the use of video for your program

for m=1:K
    y = solverIteration(y);
    plot(x,y);
    drawnow;

    vidFrame = getframe(gcf);
    % instead of gcf you can specify which figure you want to capture

    clf;

    writeVideo(video,vidFrame); % adds frames to the video

end


close(video);

此脚本是如何录制视频的示例。官方matlab site有几个例子和解释。

【讨论】:

  • 这太棒了,巴勃罗!给了我一个很好的起点……希望现在能够解决。干杯!
  • 你解决了你的问题@user3792245 吗?如果您需要帮助,请告诉我!如果没有,请将问题标记为已回答:)
  • 是的,成功了!我使用了您代码中的一些输入,但最终编写了一段全新的代码来自定义我的要求。这是视频:sreek_11-hotmail.tinytake.com/sf/Mjk5Nzc5MV84OTg2MjU4。感谢您的投入,巴勃罗!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-31
  • 2012-12-05
  • 2018-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多