问题
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])
回答1:
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.
来源:https://stackoverflow.com/questions/52757463/time-series-animation-in-matlab