idamnjanovic@60: function updateFigure(opts, figTitle, figFilename) idamnjanovic@60: idamnjanovic@60: % Copyright 2008, Ewout van den Berg and Michael P. Friedlander idamnjanovic@60: % http://www.cs.ubc.ca/labs/scl/sparco idamnjanovic@60: % $Id: updateFigure.m 1040 2008-06-26 20:29:02Z ewout78 $ idamnjanovic@60: idamnjanovic@60: % Ensure default values are available idamnjanovic@60: opts.linewidth = getOption(opts,'linewidth', []); idamnjanovic@60: opts.fontsize = getOption(opts,'fontsize', []); idamnjanovic@60: opts.markersize = getOption(opts,'markersize',[]); idamnjanovic@60: idamnjanovic@60: % Output the plots idamnjanovic@60: if opts.update idamnjanovic@60: % Set the line width, font size and marker size idamnjanovic@60: chld = [gca; get(gca,'Children')]; idamnjanovic@60: lnwd = ones(length(chld),1) * NaN; idamnjanovic@60: fnts = ones(length(chld),1) * NaN; idamnjanovic@60: mrks = ones(length(chld),1) * NaN; idamnjanovic@60: for i=1:length(chld) idamnjanovic@60: conf = get(chld(i)); idamnjanovic@60: if ~isempty(opts.linewidth) && isfield(conf,'LineWidth') idamnjanovic@60: lnwd(i) = get(chld(i),'LineWidth'); idamnjanovic@60: if (lnwd(i) == 0.5) % Default idamnjanovic@60: set(chld(i),'Linewidth',opts.linewidth); idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: if ~isempty(opts.fontsize) && isfield(conf,'FontSize') idamnjanovic@60: fnts(i) = get(chld(i),'FontSize'); idamnjanovic@60: if (fnts(i) == 10) % Default idamnjanovic@60: set(chld(i),'FontSize',opts.fontsize); idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: if ~isempty(opts.markersize) && isfield(conf,'MarkerSize') idamnjanovic@60: mrks(i) = get(chld(i),'MarkerSize'); idamnjanovic@60: if (mrks(i) == 6) % Default idamnjanovic@60: set(chld(i),'MarkerSize',opts.markersize); idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: for i=1:length(opts.figtype) idamnjanovic@60: updateFigureType(opts.update, 0, opts.figtype{i}, ... idamnjanovic@60: opts.figpath, figTitle, figFilename); idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: % Restore the line-widths, font size idamnjanovic@60: for i=1:length(chld) idamnjanovic@60: if ~isnan(lnwd(i)) idamnjanovic@60: set(chld(i),'LineWidth',lnwd(i)); idamnjanovic@60: end idamnjanovic@60: if ~isnan(fnts(i)) idamnjanovic@60: set(chld(i),'FontSize',fnts(i)); idamnjanovic@60: end idamnjanovic@60: if ~isnan(mrks(i)) idamnjanovic@60: set(chld(i),'MarkerSize',mrks(i)); idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: % Show the plot idamnjanovic@60: if opts.show idamnjanovic@60: updateFigureType(0,opts.show,'','',figTitle,''); idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: function updateFigureType(update,show,figtype,figpath,figTitle,figFilename) idamnjanovic@60: filename = [figpath,figFilename]; idamnjanovic@60: idamnjanovic@60: switch lower(figtype) idamnjanovic@60: case {'pdf'} idamnjanovic@60: cmdPostprocess = sprintf('!pdfcrop %s.pdf %s.pdf >& /dev/null', ... idamnjanovic@60: filename, filename); idamnjanovic@60: otherwise idamnjanovic@60: cmdPostprocess = []; idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: [figtype,figext] = getFigureExt(figtype); idamnjanovic@60: idamnjanovic@60: % Print the figure for output (without title) idamnjanovic@60: if update idamnjanovic@60: evalc(sprintf('print -d%s %s.%s;', figtype, filename, figext)); idamnjanovic@60: idamnjanovic@60: if ~isempty(cmdPostprocess) idamnjanovic@60: eval(cmdPostprocess); idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: idamnjanovic@60: % Add title if needed idamnjanovic@60: if show idamnjanovic@60: title(figTitle); idamnjanovic@60: end