getfigurepos.m 555 B

12345678910111213141516171819202122232425
  1. function f = getfigurepos(fig,units)
  2. % function f = getfigurepos(fig,units)
  3. %
  4. % <fig> (optional) is the figure handle. default: gcf.
  5. % <units> (optional) is 'normalized' (default) | 'points'
  6. %
  7. % return the position of <fig> in units specified by <units>.
  8. %
  9. % example:
  10. % figure; getfigurepos(gcf,'points')
  11. % input
  12. if ~exist('fig','var') || isempty(fig)
  13. fig = gcf;
  14. end
  15. if ~exist('units','var') || isempty(units)
  16. units = 'normalized';
  17. end
  18. % do it
  19. prev = get(fig,'Units');
  20. set(fig,'Units',units);
  21. f = get(fig,'Position');
  22. set(fig,'Units',prev);