11

Does anyone know if it's possible to automatically write a figure out to a .eps file in MATLAB?

I'm running a script that produces a large number of graphs, and it'd be nice if I didn't have to manually save each one!

SecretAgentMan
  • 2,690
  • 6
  • 16
  • 35
Ed James
  • 9,985
  • 15
  • 68
  • 102
  • 1
    Perhaps related [here](http://stackoverflow.com/questions/10478414/saving-a-plot-as-a-png-in-matlab). – hhh Oct 15 '12 at 02:28

4 Answers4

10

print function does that:

Print figure or save to specific file format...

print(filename,formattype) saves the current figure to a file using the specified file format, such as print('BarPlot','-dpng'). If the file name does not include an extension, then print appends the appropriate one.

print(filename,formattype,formatoptions) specifies additional options that are available for some formats.

print prints the current figure to the default printer...

gnat
  • 6,199
  • 101
  • 49
  • 71
SilentGhost
  • 264,945
  • 58
  • 291
  • 279
10

print or saveas will do the trick.

saveas(fig_handle, 'filename','eps')
print('-deps',fig_handle)
print -deps 1

If you want to specify the output file name, you're better off using saveas.

TR.
  • 2,095
  • 3
  • 15
  • 15
3

This was answered in this other question, using the PRINT command. Although that question dealt with making .tiff images, it should be straightforward to modify the code given in those answers to write a .eps.

Community
  • 1
  • 1
gnovice
  • 123,396
  • 14
  • 248
  • 352
  • I'm not loading an image in or out, this is a set of automatically generated graphs, so I'm not sure the same syntax applies. – Ed James Mar 03 '09 at 15:16
  • Although the text of the question just shows IMREAD and IMWRITE, some of the answers show how to use the PRINT function to output a plotted image. – gnovice Mar 03 '09 at 15:18
0

Suppose, you are generating N numbers of figures in a loop, then you should try the command line:

saveas(gca,sprintf('Figure%02d.pdf',N )); it produces N figures Figure1.pdf - FigureN.pdf saveas(gca,sprintf('Figure%02d.eps',N )); it produces N figures Figure1.eps - FigureN.eps

in place of gca one can use gcf also. First command line is a better solution.

Hope this will solve your issue.

Andrei Nicusan
  • 4,388
  • 1
  • 20
  • 35