Save Matlab figure without plotting it?

shahar_m picture shahar_m · Apr 28, 2011 · Viewed 17.6k times · Source

Is there a way of saving a figure plot without actually plotting it? I mean, let's say I want to save the graph for plot(1:10, (1:10).^2), can I save it without showing it?

I want to make the run time shorter by cutting off the unnecessary plotting of the figures (those will be closed anyway after saving).

Thanks!

Answer

Chris A. picture Chris A. · Apr 29, 2011

This can be done:

set(gcf,'Visible','off');
plot((1:10),(1:10).^2);
print -dpng c:\chris.png  % or whatever your print command is