function ViewerObj = deletesys(ViewerObj,indDelete);
%DELETESYS Remove systems from the LTI Viewer

%   Authors: Karen D. Gondoly: 4-6-98
%   Revised: Adam W. DiVergilio, 11-99
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.14 $  $Date: 2000/07/11 17:41:36 $

%---Remove all the Systems' data
DeletedNames = ViewerObj.SystemNames(indDelete,:);
ViewerObj.SystemNames(indDelete,:)=[];
ViewerObj.Systems(indDelete,:)=[];
ViewerObj.PlotStyles(indDelete,:)=[];

for ctU=1:length(ViewerObj.UIContextMenu)
   % For each response plot...
   RespObj = get(ViewerObj.UIContextMenu(ctU),'UserData');
   RespObjNames = get(RespObj,'SystemNames');
   % Find locations of deleted systems in RESPOBJ's system list
   indDel = find(ismember(RespObjNames,DeletedNames));
   if ~isempty(indDel)
      RespObj = deletesys(RespObj,indDel);
      %---Update the Array Selector(s)
      RespCMenu = get(RespObj,'UIcontextMenu');
      if isequal(get(RespCMenu.ArrayMenu,'Visible'),'on')
         paramsel('#delete',RespObj,indDelete)
      end
   end
end

% Refresh plots (to adjust axis limits)
%---Note: we must save ViewerObj in UserData prior to plotswitch call
%--- This will go away when UDD arrives!
set(ViewerObj.Handle,'UserData',ViewerObj);
ViewerObj = plotswitch(ViewerObj);
set(ViewerObj.Handle,'UserData',ViewerObj);
