function isvalid = validsys(plottype,sys)
%VALIDSYS  Discards systems that cannot be plotted.
%
%   ISVALID = VALIDSYS(PLOTTYPE,SYS) returns a logical vector
%   such that ISVALID(i) = 1 for systems whose response is 
%   well defined for the plot type PLOTTYPE.

%   Author(s): P. Gahinet and K. Gondoly
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.2 $  $Date: 2000/06/14 20:03:28 $

nsys = length(sys);
isvalid = logical(zeros(1,nsys));

% Eliminate NaN's (used as placeholders in SISO Tool when closed loop
% is undefined)
for i=1:nsys
   isvalid(i) = isa(sys{i},'lti');
end

% Special cases
if strcmp(plottype,'pzmap')
   % No FRD for pole/zero plot
   for i=find(isvalid)
      isvalid(i) = ~isa(sys{i},'frd');
   end
elseif any(strcmp(plottype,{'step','impulse','initial','lsim'}))
   % No FRD or improper system for time response plots
   for i=find(isvalid)
      isvalid(i) = ~isa(sys{i},'frd') & isproper(sys{i});
   end
end