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