Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a figure to a file automatically in MATLAB

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!

like image 969
Ed James Avatar asked Mar 03 '09 15:03

Ed James


People also ask

How do I save a figure automatically in MATLAB?

To save the current figure, specify fig as gcf . saveas( fig , filename , formattype ) creates the file using the specified file format, formattype .

How do I create a .fig file in MATLAB?

Save Current Figure to FIG-File To open the saved figure, use the command: openfig('PeaksFile. fig'); MATLAB creates a new figure using the saved .

What is .fig in MATLAB?

figure( n ) finds a figure in which the Number property is equal to n , and makes it the current figure. If no figure exists with that property value, MATLAB® creates a new figure and sets its Number property to n .


2 Answers

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

like image 146
SilentGhost Avatar answered Nov 11 '22 03:11

SilentGhost


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.

like image 38
TR. Avatar answered Nov 11 '22 05:11

TR.