Home > GLMdenoise > utilities > printnice.m

printnice

PURPOSE ^

function printnice(figs,mode,directory,prefix)

SYNOPSIS ^

function printnice(figs,mode,directory,prefix)

DESCRIPTION ^

 function printnice(figs,mode,directory,prefix)

 <figs> (optional) is a vector of figure numbers.  default: [gcf].
 <mode> (optional) is
   0 means .eps (using flags "-depsc2 -painters -r300").
     [0 1] means also use the flag "-loose".
   [1 n] means .png at n pixels per inch (using flags "-dpng -r(n)")
   default: 0.
 <directory> (optional) is the directory to temporarily change into
   when writing the files.  default is the current working directory.
   we automatically make the directory if it doesn't exist.
 <prefix> (optional) is the prefix of the output filename.  the prefix
   can include in it '%d' (or a variant thereof) for the figure number.
   you can pass in a number and we automatically convert it using num2str.
   default: '%d'.

 print figure windows to files in <directory>.

 note that if <prefix> has a directory that precedes the actual filename,
 we attempt to automatically make that directory.

 history:
 2011/06/29 - temporarily change PaperPositionMode to auto before printing

 example:
 figure; scatter(randn(100,1),randn(100,1),'r.'); printnice;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function printnice(figs,mode,directory,prefix)
0002 
0003 % function printnice(figs,mode,directory,prefix)
0004 %
0005 % <figs> (optional) is a vector of figure numbers.  default: [gcf].
0006 % <mode> (optional) is
0007 %   0 means .eps (using flags "-depsc2 -painters -r300").
0008 %     [0 1] means also use the flag "-loose".
0009 %   [1 n] means .png at n pixels per inch (using flags "-dpng -r(n)")
0010 %   default: 0.
0011 % <directory> (optional) is the directory to temporarily change into
0012 %   when writing the files.  default is the current working directory.
0013 %   we automatically make the directory if it doesn't exist.
0014 % <prefix> (optional) is the prefix of the output filename.  the prefix
0015 %   can include in it '%d' (or a variant thereof) for the figure number.
0016 %   you can pass in a number and we automatically convert it using num2str.
0017 %   default: '%d'.
0018 %
0019 % print figure windows to files in <directory>.
0020 %
0021 % note that if <prefix> has a directory that precedes the actual filename,
0022 % we attempt to automatically make that directory.
0023 %
0024 % history:
0025 % 2011/06/29 - temporarily change PaperPositionMode to auto before printing
0026 %
0027 % example:
0028 % figure; scatter(randn(100,1),randn(100,1),'r.'); printnice;
0029 
0030 % NOTE: removed special eps pixel mode (see old printnice.m)
0031 % SEE: figurewrite.m
0032 
0033 % input
0034 if ~exist('figs','var') || isempty(figs)
0035   figs = [gcf];
0036 end
0037 if ~exist('mode','var') || isempty(mode)
0038   mode = 0;
0039 end
0040 if ~exist('directory','var') || isempty(directory)
0041   directory = pwd;
0042 end
0043 if ~exist('prefix','var') || isempty(prefix)
0044   prefix = '%d';
0045 end
0046 if ~ischar(prefix)
0047   prefix = num2str(prefix);
0048 end
0049 
0050   olddir = pwd;
0051   mkdirquiet(directory);
0052   cd(directory);
0053 
0054 % make dir if necessary
0055 dir0 = stripfile(prefix);
0056 if ~isempty(dir0) && ~exist(dir0,'dir')
0057   mkdirquiet(dir0);
0058 end
0059 
0060 % do it
0061 for p=1:length(figs)
0062   fig = figs(p);
0063 
0064   % temporarily change
0065   prev = get(fig,'PaperPositionMode');
0066   set(fig,'PaperPositionMode','auto');
0067 
0068   switch mode(1)
0069   case 0
0070     filename = sprintf([prefix '.eps'],fig);
0071     if length(mode) > 1
0072       print(fig,'-depsc2','-painters','-r300','-loose',filename);
0073     else
0074       print(fig,'-depsc2','-painters','-r300',filename);
0075     end
0076   case 1
0077     filename = sprintf([prefix '.png'],fig);
0078     print(fig,'-dpng',['-r' num2str(mode(2))],filename);  % painters, zbuffer, opengl???  what is correct?
0079   end
0080 %  fprintf('wrote %s.\n',filename);
0081 
0082   % restore
0083   set(fig,'PaperPositionMode',prev);
0084 
0085 end
0086 
0087   cd(olddir);

Generated on Fri 01-Aug-2014 12:03:17 by m2html © 2005