function [] = printfig(filename,varargin)
% Print current figure to a .png file % % [] = PRINTFIG(FILENAME, …) % % See PRINT.M help for more information. % % FILENAME (without extension) to save to. % % PAPERSIZE (optional, default = [6 6]). Changes width and % height % % PAPERMARGINS (optional, defaults = [0.25 2.5]. % % FILETYPE defaults to ‘-dpng’ - optionally set alternatives
if nargin<1 error(‘Need to feed in a filename’); end if isempty(filename) error(‘Filename can”t be empty’); end
defaults.papersize = [6 6]; defaults.papermargins = [0.25 2.5]; defaults.filetype = ‘-dpng’; args = propval(varargin,defaults);
set(gcf,’PaperPosition’,[args.papermargins args.papersize]);
if ~isempty(strfind(filename,’.’)) error(‘Can”t print a figure to a filename with dots in it’); end
dispf(‘Printing figure %i to %s’,gcf,filename); print(args.filetype,filename);
Home - Blog - Startups - Software - Research - Writing
Email me - updated 31 Dec 2012