function rect = getrect(fig)
%GETRECT Track mouse movement with rubberbanded rectangle.
%	RECT = GETRECT(FIG) tracks the movement of a mouse-drag in
%	the figure FIG.  The mouse movement is tracked with a 
%	rubberbanded rectangle.  Returns the selected rectangle,
%	RECT = [left, bottom, width, height] in axes coordinates.

%	Clay M. Thompson 1-22-93
%	Copyright (c) 1993 by The MathWorks, Inc.
%	$Revision: 1.8 $  $Date: 1993/07/01 19:24:38 $

if nargin<1, fig = gcf; end

figure(fig)
curse = get(gcf,'pointer');
set(gcf,'pointer','crosshair');

btndown = get(gcf,'windowbuttondownfcn');
btnup = get(gcf,'windowbuttonupfcn');
btnmotion = get(gcf,'windowbuttonmotionfcn');
set(gcf,'windowbuttondownfcn','','windowbuttonupfcn','', ...
        'windowbuttonmotionfcn','')

waitforbuttonpress;
Pt1 = get(gca,'currentpoint');
rbbox([get(gcf,'currentpoint') 0 0],get(gcf,'currentpoint'))
Pt2 = get(gca,'currentpoint');
rect = [min([Pt1(1,1:2);Pt2(1,1:2)]) abs(Pt2(1,1:2)-Pt1(1,1:2))];

set(gcf,'pointer',curse);
set(gcf,'windowbuttondownfcn',btndown,'windowbuttonupfcn',btnup, ...
        'windowbuttonmotionfcn',btnmotion)
