comparison Problems/private/updateFigure.m @ 61:42fcbcfca132

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