Wednesday, June 04, 2008

Export figures in Matlab without displaying them

Assuming you have a lot of figures to plot, but you do not want to wait and see them in Matlab's figure window. There is a way you can export all of your figures without displaying them. This might also save you some time, since you are drawing them on the screen.

Here is how :

% Create a figure with visibility off
f = figure('Visible','off');
% Then do your plot
plot
% Finally export the plot as an image
print('-dpng', 'test.png');

You can also make this in a loop (Which is very probable if you have too many figures).
Do this

for i:1, n
f = figure('Visible','off');
plot
filename = sprintf('plot-%d',i);
print('-dpng', filename);
end

This will give you 'n' png images with your plots in it.

11 comments:

Anonymous said...

Hi !
Wow, it helps so much!
Was looking for this for VERY long time.

Anonymous said...

Thanks. Very helpful.

DippingDots said...

Thanks!Very Helpful

Anonymous said...

Thank you, quite useful!

felipe said...

very simple and so useful... thanks!

Hadi said...

Fantastic. Thanks a lot.

Anonymous said...

thanks Bro, by the way the one over me is gay!

Unknown said...

but the problem is, that u cannot save .fig like that. They remain invisible after saving. Does anyone has the solution for that?

ViKing said...

Thanks, this is useful

Unknown said...

I have the same problem. I can not open saved invisible figure. Does someone have a tip?

Unknown said...

To Vladimir Zaplava, you can see the figure again using this code :

set(gcf,'visible','on')

Hope that help