pb_savefig.m 1.14 KB
Newer Older
Jesse Heckman's avatar
Jesse Heckman committed
1
function pb_savefig(varargin)
Jesse Heckman's avatar
Jesse Heckman committed
2
% PB_SAVEFIG(varargin)
Jesse Heckman's avatar
Jesse Heckman committed
3
%
Jesse Heckman's avatar
Jesse Heckman committed
4
% PB_SAVEFIG saves a figure in a directory.
Jesse Heckman's avatar
Jesse Heckman committed
5
%
Jesse Heckman's avatar
Jesse Heckman committed
6
7
% See also PB_SAVEFIGS

Jesse Heckman's avatar
Jesse Heckman committed
8
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
9

Jesse Heckman's avatar
Jesse Heckman committed
10
11
12
   n = nargin;

   fig     = pb_keyval('fig',varargin);
Jesse Heckman's avatar
Jesse Heckman committed
13
   
Jesse Heckman's avatar
Jesse Heckman committed
14
   fname   = pb_keyval('fname',varargin);
Jesse Heckman's avatar
Jesse Heckman committed
15
16
   dir     = pb_keyval('dir',varargin,[pb_datadir 'PhD/Figures/']);
   ext     = pb_keyval('ext',varargin,'pdf');
Jesse Heckman's avatar
Jesse Heckman committed
17
18
   cd(dir);

Jesse Heckman's avatar
Jesse Heckman committed
19
   figure(fig);
Jesse Heckman's avatar
Jesse Heckman committed
20
   g = groot;
Jesse Heckman's avatar
Jesse Heckman committed
21
22

   if n == 0 && ~isempty(g.Children)
Jesse Heckman's avatar
Jesse Heckman committed
23
24
25
26
27
28
      filter = {'*.fig';'*.pdf'};
      h = get(g,'currentFigure');
      [fname, path] = uiputfile(filter,[],strcat('Fig_',num2str(h.Number)));
   elseif n >= 1 && ~isempty(g.Children)
      path = dir;
   end
Jesse Heckman's avatar
Jesse Heckman committed
29
30
31

   h = get(g,'currentFigure'); 
   path = [path '/' fname];
Jesse Heckman's avatar
Jesse Heckman committed
32
33
   savefig(h,path);
   saveas(h,path,ext);
Jesse Heckman's avatar
Jesse Heckman committed
34
35
36
37
38
39
40
41
42
end
 
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %