Home > atmlab > graphs > save_figure_multi.m

save_figure_multi

PURPOSE ^

save figure in multiple formats

SYNOPSIS ^

function save_figure_multi(fig, pathbase, varargin)

DESCRIPTION ^

 save figure in multiple formats

 Save a figure in multiple formats.  Pass the basename and this function
 will write basename.{png,eps,fig}, for example.

 FORMAT

   save_figure_multi(fig, pathbase, format1, format2, ...)

 IN

   fig         Figure handle, figure to be stored
   format1     String of first format to store to.  The string is equal to
               the extention: 'png', 'pdf', 'eps', etc.  Special cases:
               - 'fig' will store a Matlab figure object
               - 'ps' and 'eps' will store psc and epsc, respectively

 OUT

   none, but writes a file

 EXAMPLE

   >> save_figure_multi(gcf(), 'plots/this_plot', 'png', 'eps', 'fig');

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

save_figure_multi.m

SOURCE CODE ^

0001 function save_figure_multi(fig, pathbase, varargin)
0002 
0003 % save figure in multiple formats
0004 %
0005 % Save a figure in multiple formats.  Pass the basename and this function
0006 % will write basename.{png,eps,fig}, for example.
0007 %
0008 % FORMAT
0009 %
0010 %   save_figure_multi(fig, pathbase, format1, format2, ...)
0011 %
0012 % IN
0013 %
0014 %   fig         Figure handle, figure to be stored
0015 %   format1     String of first format to store to.  The string is equal to
0016 %               the extention: 'png', 'pdf', 'eps', etc.  Special cases:
0017 %               - 'fig' will store a Matlab figure object
0018 %               - 'ps' and 'eps' will store psc and epsc, respectively
0019 %
0020 % OUT
0021 %
0022 %   none, but writes a file
0023 %
0024 % EXAMPLE
0025 %
0026 %   >> save_figure_multi(gcf(), 'plots/this_plot', 'png', 'eps', 'fig');
0027 
0028 formats = varargin;
0029 if isempty(formats)
0030     logtext(atmlab('OUT'), 'No formats specified, not writing any files\n');
0031 end
0032 for i = 1:length(formats)
0033     format = formats{i};
0034     outname = [pathbase '.' format];
0035     logtext(atmlab('OUT'), 'Storing %s\n', outname);
0036     switch format
0037         case {'ps', 'eps'}
0038             print(fig, sprintf('-d%sc', format), outname);
0039         case {'fig'}
0040             hgsave(fig, outname);
0041         otherwise
0042             print(fig, sprintf('-d%s', format), outname);
0043     end
0044 end
0045 
0046 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005