Adi279
Adi279

Reputation: 148

making a movie in matlab for a complex plot

I have written a FEA solver in matlab. I need to plot the results as a movie. but each frame will easily take more than a minute to plot due to the complexity and huge amount of data to plot. Is there any way I can directly save the frames of the plot as a movie, without matlab popping a new frame every few seconds? I need to save these frames into a movie , with matlab doing the work in the background and finally output a movie that is seamless.

Thanks in advance!!

With Regards

Upvotes: 0

Views: 72

Answers (1)

Staus
Staus

Reputation: 651

You can use getframe() to grab basically a screenshot of your plot window, then use the VideoWriter class to add these screenshots to a movie that you can play back later. Or you can output the frames from getframe() as a GIF, or as individual images, or whatever, once you have those grabbed images.

Here's a hastily coded example:

fig = figure();
ax = axes('Parent', fig);

writeObj = VideoWriter('C:\path\to\your\folder\VideoName.avi');
open(writeObj);

x = 1:10;
m = 1:10;

for k = 1:numel(m)

    y = x*m(k);
    plot(ax, x, y);
    drawnow;

    frm = getframe(fig);
    writeVideo(writeObj, frm);

end

close(writeObj);

Upvotes: 1

Related Questions