function []=plotresults(T,Y,Yr,Ymin,Ymax,U,Ur,Umin,Umax)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% []=plotresults(T,Y,Yr,Ymin,Ymax,U,Ur,Umin,Umax)
% 
% Plot results
% Output plot of: - output / measurement                 (black -)	
%                 - setpoint                             (red  --)	
%                 - upper and lower bounds               (blue  *)	
%
% Input plot of:  - inputs                               (black -)
%                 - ideal value                          (red  --)
%                 - upper and lower bounds               (blue  *)
%
% INPUTS:
%  T   : Time vector (step number) [1 x dimT]      
%  Y   : Output / measurement      [dimy x dimT] 
%  Yr  : Setpoint                  [dimy x dimT]    
%  Ymin: Lower bound               [dimy x dimT]
%  Ymax: Upper bound               [dimy x dimT]
%  Uk  : Input (current)           [dimu x dimT] 
%  Ur  : Ideal value               [dimu x dimT]    
%  Umin: Lower bound               [dimu x dimT]
%  Umax: Upper bound               [dimu x dimT]
%
% OUTPUTS:
%
% Written by: msg20001203
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dimu=size(U,1);
dimy=size(Y,1);

%Outputs
%figure(20); clf;
for ny=1:dimy
   figure(20+ny);subplot(2,1,1);
   if isempty(Ymax)
      plot(T,Y(ny,:),'k-',T,Yr(ny,:),'r--');
   else
      plot(T,Y(ny,:),'k-',T,Yr(ny,:),'r--',T,Ymax(ny,:),'b*',T,Ymin(ny,:),'b*');
   end   
   ylabel(sprintf('y_%d',ny));
end   
xlabel('k');

%Inputs
%figure(21); clf;
for nu=1:dimu
   figure(20+nu);subplot(2,1,2);
   if isempty(Umax)
      plot(T,U(nu,:),'k-',T,Ur(nu,:),'r--');
   else
      plot(T,U(nu,:),'k-',T,Ur(nu,:),'r--',T,Umax(nu,:),'b*',T,Umin(nu,:),'b*');
   end
   ylabel(sprintf('u_%d',nu));
end   
xlabel('k');
