function moveax(flag)
%MOVEAX  Installs a simple axis mover for the current axes

% From The Mathworks Newsletter Vol 7, No. 4

if nargin==0
  flag='init';
end

% initialization
if (strcmp(flag,'init'))
  set(gcf,'Units','Normalized');	
  set(gca,'ButtonDownFcn','moveax(''down'')');
  
  % mouse button down
elseif strcmp(flag,'down')
  loc=get(gcf,'CurrentPoint');
  set(gca,'UserData',loc);
  set(gcf,'WindowButtonMotionFcn','moveax(''move'')')
  set(gcf,'WindowButtonUpFcn','moveax(''up'')')
  
  % mouse motion
elseif strcmp(flag,'move')
  loc=get(gcf,'CurrentPoint');
  old_loc=get(gca,'UserData');  
  pos = get(gca,'Position');
  set(gca,'position',[pos(1)+loc(1)-old_loc(1) pos(2)+loc(2)-old_loc(2) pos(3:4)]);
  set(gca,'UserData',loc);
  
  % mouse button up
elseif strcmp(flag,'up')
  set(gcf,'WindowButtonMotionFcn','')
  set(gcf,'WindowButtonUpFcn','')
  
end
