11

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!

shahar_m
  • 3,461
  • 5
  • 41
  • 61
  • 7
    possible duplicate of [How do I plot to an image and save result without displaying it, in matlab](http://stackoverflow.com/questions/963674/how-do-i-plot-to-an-image-and-save-result-without-displaying-it-in-matlab) – Jonas Apr 28 '11 at 12:27
  • @Jonas: Great, there are good answers there. – shahar_m Apr 30 '11 at 16:59

2 Answers2

16

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
Chris A.
  • 6,817
  • 2
  • 25
  • 43
7

There is also the saveas(h,'filename.ext') function which can save a figure in some formats.

Mohsen
  • 101
  • 1
  • 6