annotate DL/RLS-DLA/private/updateFigure.m @ 63:e08af264ef93

(none)
author idamnjanovic
date Tue, 15 Mar 2011 12:23:35 +0000
parents ad36f80e2ccf
children
rev   line source
idamnjanovic@60 1 function updateFigure(opts, figTitle, figFilename)
idamnjanovic@60 2
idamnjanovic@60 3 % Copyright 2008, Ewout van den Berg and Michael P. Friedlander
idamnjanovic@60 4 % http://www.cs.ubc.ca/labs/scl/sparco
idamnjanovic@60 5 % $Id: updateFigure.m 1040 2008-06-26 20:29:02Z ewout78 $
idamnjanovic@60 6
idamnjanovic@60 7 % Ensure default values are available
idamnjanovic@60 8 opts.linewidth = getOption(opts,'linewidth', []);
idamnjanovic@60 9 opts.fontsize = getOption(opts,'fontsize', []);
idamnjanovic@60 10 opts.markersize = getOption(opts,'markersize',[]);
idamnjanovic@60 11
idamnjanovic@60 12 % Output the plots
idamnjanovic@60 13 if opts.update
idamnjanovic@60 14 % Set the line width, font size and marker size
idamnjanovic@60 15 chld = [gca; get(gca,'Children')];
idamnjanovic@60 16 lnwd = ones(length(chld),1) * NaN;
idamnjanovic@60 17 fnts = ones(length(chld),1) * NaN;
idamnjanovic@60 18 mrks = ones(length(chld),1) * NaN;
idamnjanovic@60 19 for i=1:length(chld)
idamnjanovic@60 20 conf = get(chld(i));
idamnjanovic@60 21 if ~isempty(opts.linewidth) && isfield(conf,'LineWidth')
idamnjanovic@60 22 lnwd(i) = get(chld(i),'LineWidth');
idamnjanovic@60 23 if (lnwd(i) == 0.5) % Default
idamnjanovic@60 24 set(chld(i),'Linewidth',opts.linewidth);
idamnjanovic@60 25 end
idamnjanovic@60 26 end
idamnjanovic@60 27 if ~isempty(opts.fontsize) && isfield(conf,'FontSize')
idamnjanovic@60 28 fnts(i) = get(chld(i),'FontSize');
idamnjanovic@60 29 if (fnts(i) == 10) % Default
idamnjanovic@60 30 set(chld(i),'FontSize',opts.fontsize);
idamnjanovic@60 31 end
idamnjanovic@60 32 end
idamnjanovic@60 33 if ~isempty(opts.markersize) && isfield(conf,'MarkerSize')
idamnjanovic@60 34 mrks(i) = get(chld(i),'MarkerSize');
idamnjanovic@60 35 if (mrks(i) == 6) % Default
idamnjanovic@60 36 set(chld(i),'MarkerSize',opts.markersize);
idamnjanovic@60 37 end
idamnjanovic@60 38 end
idamnjanovic@60 39 end
idamnjanovic@60 40
idamnjanovic@60 41 for i=1:length(opts.figtype)
idamnjanovic@60 42 updateFigureType(opts.update, 0, opts.figtype{i}, ...
idamnjanovic@60 43 opts.figpath, figTitle, figFilename);
idamnjanovic@60 44 end
idamnjanovic@60 45
idamnjanovic@60 46 % Restore the line-widths, font size
idamnjanovic@60 47 for i=1:length(chld)
idamnjanovic@60 48 if ~isnan(lnwd(i))
idamnjanovic@60 49 set(chld(i),'LineWidth',lnwd(i));
idamnjanovic@60 50 end
idamnjanovic@60 51 if ~isnan(fnts(i))
idamnjanovic@60 52 set(chld(i),'FontSize',fnts(i));
idamnjanovic@60 53 end
idamnjanovic@60 54 if ~isnan(mrks(i))
idamnjanovic@60 55 set(chld(i),'MarkerSize',mrks(i));
idamnjanovic@60 56 end
idamnjanovic@60 57 end
idamnjanovic@60 58
idamnjanovic@60 59 end
idamnjanovic@60 60
idamnjanovic@60 61 % Show the plot
idamnjanovic@60 62 if opts.show
idamnjanovic@60 63 updateFigureType(0,opts.show,'','',figTitle,'');
idamnjanovic@60 64 end
idamnjanovic@60 65
idamnjanovic@60 66
idamnjanovic@60 67
idamnjanovic@60 68 function updateFigureType(update,show,figtype,figpath,figTitle,figFilename)
idamnjanovic@60 69 filename = [figpath,figFilename];
idamnjanovic@60 70
idamnjanovic@60 71 switch lower(figtype)
idamnjanovic@60 72 case {'pdf'}
idamnjanovic@60 73 cmdPostprocess = sprintf('!pdfcrop %s.pdf %s.pdf >& /dev/null', ...
idamnjanovic@60 74 filename, filename);
idamnjanovic@60 75 otherwise
idamnjanovic@60 76 cmdPostprocess = [];
idamnjanovic@60 77 end
idamnjanovic@60 78
idamnjanovic@60 79 [figtype,figext] = getFigureExt(figtype);
idamnjanovic@60 80
idamnjanovic@60 81 % Print the figure for output (without title)
idamnjanovic@60 82 if update
idamnjanovic@60 83 evalc(sprintf('print -d%s %s.%s;', figtype, filename, figext));
idamnjanovic@60 84
idamnjanovic@60 85 if ~isempty(cmdPostprocess)
idamnjanovic@60 86 eval(cmdPostprocess);
idamnjanovic@60 87 end
idamnjanovic@60 88 end
idamnjanovic@60 89
idamnjanovic@60 90 % Add title if needed
idamnjanovic@60 91 if show
idamnjanovic@60 92 title(figTitle);
idamnjanovic@60 93 end