Question

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!

Cheers, Ed

Was it helpful?

Solution

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...

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top