Write a figure to a file automatically in MATLAB

依然范特西╮ 提交于 2020-01-11 00:21:07

问题


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!


回答1:


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




回答2:


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.




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




回答4:


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.



来源:https://stackoverflow.com/questions/606768/write-a-figure-to-a-file-automatically-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!