Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

MATLAB getframe captures whatever is on screen

Date: 2022-11-23 12:21:42

I am trying to create a movie from my MATLAB plot. When I call getframe, it "usually" captures the plot image, but sometimes if there is something else active on the screen (which is normal if I continue to use the computer) it captures whatever window is active. Is there another way to grab the image of the active figure?

e.g.

fig = figure;
aviobj = avifile('sample.avi','compression','None');
for i=1:t
    clf(fig);
    plot(...); % some arbitrary plotting
    hold on;
    plot(...); % some other arbitrary plotting
    axis([0 50 0 50]);
    aviobj = addframe(aviobj, getframe(fig));
end
aviobj = close(aviobj); 

Answers: 

OK, found the solution; instead of 

 

aviobj = addframe(aviobj, getframe(fig)); 

sending the figure handle directly to addframe is enough: 

 

 aviobj = addframe(aviobj, fig);

 


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com