필터 지우기
필터 지우기

Looping a function m-file, figures not closing

조회 수: 1 (최근 30일)
Michael
Michael 2011년 11월 20일
Hi,
I'm running a script which repeatedly calls a function I wrote (using a for loop). In this function there is a command to plot some data, save it to a .jpg, save the workspace to a .mat, then close the figure.
If I run the function on its own it does all this perfectly, but when I run the script, the function plots the image, saves it, but doesn't close it. The figure hangs there until it's time to plot it again in the next iteration.
I can't work out why MATLAB is not processing this command.
side question: is there a way to plot an image, save it, but not actually have it pop up? This code takes hours to run and it keeps minimising my screen when I'm watching the TV!
Thanks,
Mike

채택된 답변

Jan
Jan 2011년 11월 20일
I assume a DRAWNOW after closing the figure might solve the problem.
Opening new figures needs a lot of time. It is much faster to open one figure only and update the axes only, or even better the drawn object:
tic;
for i = 1:100
FigH = figure;
plot(1:10, rand(1, 10));
drawnow;
delete(FigH);
end
toc;
% >> Elapsed time is 15.660328 seconds.
tic;
FigH = figure;
LineH = plot(1:10, rand(1, 10));
for i = 1:100
set(LineH, 'YData', rand(1, 10));
drawnow;
end
toc;
% >> Elapsed time is 0.914224 seconds.

추가 답변 (2개)

Naz
Naz 2011년 11월 20일
Try to make the figure invisible:
set(gcf, 'Visible', 'off')

Michael
Michael 2011년 11월 21일
Thanks, both comments helped.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by