function Extent = datext(ObjectHandles,XYflag,scale)
%DATEXT  Computes X or Y extent of graphical data.
%
%   EXTENT = DATEXT(ObjectHandles,XYFLAG) computes the X or Y extent
%   of the response data contained in the HG objects with handles 
%   ObjectHandles.  The vector EXTENT contains the min and max values 
%   of the Xdata (when XYFLAG = 'x') or Ydata (when XYFLAG = 'y').
%   
%   EXTENT = DATEXT(ObjectHandles,XYFLAG,'log') specifies a log scale
%   on the X or Y axis (used to set default extent when no data is 
%   available.  The scale is assumed 'linear' by default.

%   Author: P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.2 $   $Date: 2000/06/14 19:59:09 $

Extent = zeros(0,2);

switch lower(XYflag)
case 'x'
   for h=ObjectHandles(:)'
      Xdata = get(h,'Xdata'); 
      Extent = [min([Extent(:,1) ; min(Xdata)]) , ...
            max([Extent(:,2) ; max(Xdata)])];
   end
   
   % Use scale-dependent default if there is no plotted data
   if isempty(Extent)
      if nargin<3 | strcmp(scale,'linear'),
         Extent = [0 1];
      else
         Extent = [0.1 10];
      end
   end
   
case 'y'
   for h=ObjectHandles(:)'
      Ydata = get(h,'Ydata'); 
      Extent = [min([Extent(:,1) ; min(Ydata)]) , ...
            max([Extent(:,2) ; max(Ydata)])];
   end
   
   % Use default if there is no plotted data
   if isempty(Extent)
      if nargin<3 | strcmp(scale,'linear'),
         Extent = [0 1];
      else
         Extent = [0.1 10];
      end
   end
   
otherwise
   error('Second argument must be the string ''x'' or ''y''.')
end
