function PlotStyle = setstyle(RespObj,PlotStyle,NumSys)
%SETSTYLE  Resolves undefined plot styles for response plots.
% 
%    PLOTSTYLES = SETSTYLE(RespObj,PLOTSTYLES,NumSys) resolves undefined (empty)
%    plot styles by cycling through the available colors, markers, and linestyles.
%    SETSTYLE returns plot styles of the form 
%         {Color LineStyle Marker Legend} 
%    where Color is an RGB triplet and Legend is the corresponding legend string.  
%    NumSys specifies the number of pre-existing models in HOLD mode.

%    P. Gahinet and K. Gondoly, 5-99
%    Copyright 1986-2000 The MathWorks, Inc. 
%    $Revision: 1.2 $  $Date: 2000/06/14 20:07:32 $

Cvals = RespObj.ColorOrder; 
numC = size(Cvals,1);
Lvals = RespObj.LineStyleOrder;
numL = length(Lvals);
Mvals = RespObj.MarkerOrder;
numM = length(Mvals);

% Find unspecified plot styles
UnDefStyle = find(cellfun('isempty',{PlotStyle.Color}));

% Resolve unspecified plot styles
for i=1:length(UnDefStyle),
   UnDefRank = NumSys+i-1;
   isys = UnDefStyle(i);
   if get(0,'ScreenDepth')==1 % Monochrome screen
      PlotStyle(isys).Color = [1 1 1];
      Cstr = 'white';
      LL = Lvals{rem(UnDefRank,numL)+1};
      MM = Mvals{rem(fix(UnDefRank/numL),numM)+1};
   else
      [PlotStyle(isys).Color,Cstr] = deal(Cvals{rem(UnDefRank,numC)+1,:});
      MM = Mvals{rem(fix(UnDefRank/numC),numM)+1};
      LL = Lvals{rem(fix(UnDefRank/numC/numM),numL)+1};
   end   
   PlotStyle(isys).LineStyle = LL;
   PlotStyle(isys).Marker = MM;
   PlotStyle(isys).Legend = legdstr(Cstr,LL,MM);
end

