function f = getfigurepos(fig,units) <fig> (optional) is the figure handle. default: gcf. <units> (optional) is 'normalized' (default) | 'points' return the position of <fig> in units specified by <units>. example: figure; getfigurepos(gcf,'points')
0001 function f = getfigurepos(fig,units) 0002 0003 % function f = getfigurepos(fig,units) 0004 % 0005 % <fig> (optional) is the figure handle. default: gcf. 0006 % <units> (optional) is 'normalized' (default) | 'points' 0007 % 0008 % return the position of <fig> in units specified by <units>. 0009 % 0010 % example: 0011 % figure; getfigurepos(gcf,'points') 0012 0013 % input 0014 if ~exist('fig','var') || isempty(fig) 0015 fig = gcf; 0016 end 0017 if ~exist('units','var') || isempty(units) 0018 units = 'normalized'; 0019 end 0020 0021 % do it 0022 prev = get(fig,'Units'); 0023 set(fig,'Units',units); 0024 f = get(fig,'Position'); 0025 set(fig,'Units',prev);