I am using MATLAB's movie() function to make a movie of a large amount of time series data. With its current instantiation, it will take about 14 hours to finish. What can I do to better optimize it?
The biggest thing I am trying to do is suppress drawing the plot to the screen each time while still updating it for the getframe() function.
An abbreviated version of my code is:
t = 0:1000000; % I have about 10^6 data points
x = sin(t); % Let's pretend the data I'm plotting is the sine function
y = cos(t); % I have multiple data series being plotted in 'snapshots'
num_frames = length(t);
movie_length = 100; % seconds
fps = 60;
for k = 1:num_frames
clf; hold on;
plot(1, x(k),'bo')
plot(2, y(k),'bo')
ax = gca;
ax.XLim = [0 1];
ax.YLim = [-1,1];
f(k) = getframe;
end
movie(f,1,fps)
Here is one version which speeds it up by approximatly a factor of two on my machine. I have reduced the number of points to
10^3.Note that without
getframe, the second version is about 100 times faster. thus, If you know how to compute thecdataof a single frame, it might be much faster than to plot the data and usegetframe.One remark: I was not able to copy&paste&run your code without errors. Even if written quickly from mind, it would be nice if you could test it for errors before posting.