function configaxes(RespObj)
%CONFIGAXES  Reconfigures visible axes for Response Objects
%
%   Generates the correct grid of plot axes and reparent the response
%   handles.

%   Authors: Karen Gondoly 3-18-98.
%   Revised: Adam W. Divergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.4 $  $Date: 2000/06/14 20:07:28 $

% RE: Invoked by axes grouping and I/O channel selection

LTIdisplayAxes = RespObj.PlotAxes;
ResponseHandles = RespObj.ResponseHandles;

%---Hide the current plot axes
set(LTIdisplayAxes,'visible','off')

%---Get active grid of axis and selected input and output channels
[OnY,OnU,Ysel,Usel] = axisvis(RespObj);

%---Get positions for visible axes based on number of axes in new grid
Ny = length(OnY); 
Nu = length(OnU);
AxesPos = axispos(Ny,Nu,RespObj.BackgroundAxes);

%---Resize axes in new axis grid
ResizeAxes = LTIdisplayAxes(OnY,OnU);
axunits = get(ResizeAxes(1,1),'Units');
if strcmpi(axunits,'pixels')
   set(ResizeAxes(:),{'Position'},AxesPos(:));
else
   set(ResizeAxes(:),'Units','pixels',{'Position'},AxesPos(:),'Units',axunits);
end

%---Re-parent the ResponseHandles
switch RespObj.AxesGrouping
case 'none', 
   % No grouping
   for j=1:Nu,
      for i=1:Ny,
         for ctSys=1:length(ResponseHandles)   
            RH = ResponseHandles{ctSys}{Ysel(i),Usel(j)};
            set(cat(1,RH{:}),'Parent',ResizeAxes(i,j))
         end
      end
   end
   
case 'all', 
   % Group all
   if any(strcmp(RespObj.ResponseType,{'bode','margin'}))
      for ctSys=1:length(ResponseHandles)
         RHG = cat(1,ResponseHandles{ctSys}{Ysel(1:2:end),Usel});
         set(cat(1,RHG{:}),'Parent',ResizeAxes(1))
         RHP = cat(1,ResponseHandles{ctSys}{Ysel(2:2:end),Usel});
         set(cat(1,RHP{:}),'Parent',ResizeAxes(2))
      end
   else
      for ctSys=1:length(ResponseHandles)
         RH = cat(1,ResponseHandles{ctSys}{Ysel,Usel});
         set(cat(1,RH{:}),'Parent',ResizeAxes)
      end
   end
   
case 'inputs', 
   % Group inputs
   for i=1:Ny,
      for ctSys=1:length(ResponseHandles)   
         RH = cat(1,ResponseHandles{ctSys}{Ysel(i),Usel});
         set(cat(1,RH{:}),'Parent',ResizeAxes(i,1))
      end
   end
   
case 'outputs', 
   % Group outputs
   if any(strcmp(RespObj.ResponseType,{'bode','margin'}))
      for j=1:Nu,
         for ctSys=1:length(ResponseHandles)
            RHG = cat(1,ResponseHandles{ctSys}{Ysel(1:2:end),Usel(j)});
            set(cat(1,RHG{:}),'Parent',ResizeAxes(1,j))
            RHP = cat(1,ResponseHandles{ctSys}{Ysel(2:2:end),Usel(j)});
            set(cat(1,RHP{:}),'Parent',ResizeAxes(2,j))
         end
      end
   else
      for j=1:Nu,
         for ctSys=1:length(ResponseHandles)   
            RH = cat(1,ResponseHandles{ctSys}{Ysel,Usel(j)});
            set(cat(1,RH{:}),'Parent',ResizeAxes(1,j))
         end
      end
   end
end

%---Turn axes visibility on
set(ResizeAxes,'visible','on')

