image thumbnail
genprint(fname,append)
function genprint(fname,append)
%
% genprint(fname,append) 
% ~~~~~~~~~~~~~~~~~~~~~~
% This function saves a plot to a file.  If
% the file exists, it is erased first unless
% the append option is specified.
%
% fname  - name of file to save plot to
%          without a filename extension
% append - optional, if included plot is
%          appended to file fname 
%          (specific to format)
%
% SYSTEM DEPENDENT ROUTINE
%
% User m functions called:  none
%----------------------------------------------

%...Define these appropriately
ext=['.pdf']; % filename extension to use
opt=['pdf'];  % option for print command

%...Append extension to filename
file_name=[fname,ext];

%...Use correct command for different systems
if ispc
  erase_cmd=['delete ', file_name];
elseif isunix
  erase_cmd=['!rm ', file_name];
else
  disp(' ');
  disp('Unknown system type in genprint');
  return;
end

% Save to file
if nargin == 1
  if exist(file_name)==2 
    eval(erase_cmd); 
  end
  eval(['print -d',opt,' ',fname]);
else
  %eval(['print -d',opt,' -append ',fname]);
  disp('genprint: Append option not defined');
end

Contact us at files@mathworks.com