问题描述
我对使用Matlab中的时间序列不熟悉,并且正在为实现这一目标而苦苦挣扎.我在这11个位置(见下面的代码)有时间序列的热传递数据(以1微秒为步长,以20毫秒为周期)(请参见下面的代码).对于如何将它们放在一起以能够在每个时间步生成图并在每个时间步使用 getframe 制作动画,我一无所知.对此方法的任何帮助将不胜感激.这是指向11个数据文件的链接,在第1列提供时间,在第2列提供热传递:https://drive.google.com/open?id=1oDAdapqvL-blecb7BOLzxpeiJBsqLd59
请随时建议在这种情况下也可能更好的任何其他工具(matplotlib/plotly等).万分感谢!
关闭所有全部清除x1 = 399.5x2 = 400.5y0 = 0y1 = 4y2 = 8y3 = 12y4 = 16y5 = 20y6 = -4y7 = -8y8 = -12y9 = -16y10 = -20%第一行的量规位置将为[x1,y1],[x1,y3],[x1,y5],[x1,y6],[x1,y8],%[x1,y10]%第二行的量规位置将为[x2,y0],[x2,y2],[x2,y4],[x2,y7],%[x2,y9]数字图(x1,y1,'r.',x1,y3,'r.',x1,y5,'r.',x1,y6,'r.',x1,y8,'r.',x1,y10,'r.')抓住绘图(x2,y0,'b.',x2,y2,'b.',x2,y4,'b.',x2,y7,'b.',x2,y9,'b.')轴([390 410 -30 30])
在Matlab中,您可以使用 getFrame
和 writeVideo
函数.对于一个非常普通的案例,我会加以解释,然后将其应用于您的案例.
假设我们有一个图,该图使用示例函数 solverIteration
(组成...)在for循环内的每次迭代(更改PDE等时经常发生)中更改其数据.我们正在域 x
上绘制矢量 y
.
要录制视频,我们必须执行以下操作:
video = VideoWriter('myVideo.avi');%创建一个视频对象打开视频);%打开视频源-限制在程序中使用视频对于m = 1:Ky = SolverIteration(y);情节(x,y);拉多vidFrame = getframe(gcf);%而不是gcf,您可以指定要捕获的图形clf;writeVideo(video,vidFrame);%将帧添加到视频结尾关闭(视频);
此脚本是如何录制视频的示例.在官方 matlab网站中有一些示例和说明..>
I am new to working with time series in Matlab and am struggling with getting this going. I have time series heat-transfer data (over a period of 20ms in steps of 1 microsecond) at these 11 locations (see code below). I am clueless as to how I could put them together to be able to generate a plot at each time step and use getframe at each timestep to make an animation. Any help on how to get started with this would be much appreciated. Here is a link to the 11 data files, providing time on column1 and heat transfer on column2: https://drive.google.com/open?id=1oDAdapqvL-blecb7BOLzxpeiJBsqLd59
Please feel free to suggest any other tools (matplotlib/plotly etc.) that may be better in this scenario as well. Thanks a ton!
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])
In Matlab you can use, as you said the getFrame
and writeVideo
functions. Ill explain it for a very general case, which you can then apply to yours.
Let's say we have a plot that changes it's data at every iteration inside a for loop (happens frequently when solving PDEs and so on) with an exemplary function solverIteration
(made up...). We are plotting a vector y
over our domain x
.
In order to record the video we have to do the following:
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);
This script is an example for how to record a video. There are several examples and explanations at the official matlab site.
这篇关于Matlab中的时间序列动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!