Is there a command in MATLAB which allows saving a figure in FIG or JPEG or both formats automatically?
Click File > Generate Code.... The generated code displays in the MATLAB Editor. Save the code by clicking File > Save As. Generated files do not store the data necessary to recreate the graph, so you must supply the data arguments.
The best method for storing a figure's properties, then resetting them at a later time, is to use the SAVEAS function to save the figure as a FIG-file.
To export data from the MATLAB® workspace using one of the standard graphics file formats, use the imwrite function. Using this function, you can export data in formats such as the Tagged Image File Format (TIFF), Joint Photographic Experts Group (JPEG), and Portable Network Graphics (PNG).
Open Figure Saved in MATLAB Figure FileCreate a surface plot and save the figure as a MATLAB figure file. Then, close the figure. Open the saved figure.
Use saveas:
h=figure; plot(x,y,'-bs','Linewidth',1.4,'Markersize',10); % ... saveas(h,name,'fig') saveas(h,name,'jpg')
This way, the figure is plotted, and automatically saved to '.jpg' and '.fig'. You don't need to wait for the plot to appear and click 'save as' in the menu. Way to go if you need to plot/save a lot of figures.
If you really do not want to let the plot appear (it has to be loaded anyway, can't avoid that, else there is also nothing to save), you can hide it:
h=figure('visible','off')
When using the saveas function the resolution isn't as good as when manually saving the figure with File-->Save As..., It's more recommended to use hgexport instead, as follows:
hgexport(gcf, 'figure1.jpg', hgexport('factorystyle'), 'Format', 'jpeg');
This will do exactly as manually saving the figure.
source: http://www.mathworks.com/support/solutions/en/data/1-1PT49C/index.html?product=SL&solution=1-1PT49C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With