% function newsys = sclout(sys,outputs,fac)
%
%   Scale specified outputs (rows) of a SYSTEM (VARYING)
%   matrix by a scalar number FAC.
%
%   See also: *, MMULT, MSCL, SCLOUT, SCLIV and SEL.

function newsys = sclout(sys,outputs,fac)
if nargin < 3
  disp('usage: newsys = sclout(sys,outputs,fac)');
  return
 end
 [nro,nco] = size(outputs);
 [mtype,mrows,mcols,mnum] = minfo(sys);
 if max([nro,nco]) > mrows & min([nro,nco]) > 1
   error('too many outputs (rows) specified')
   return
 end
 [nrf,ncf] = size(fac);
 if nrf == 1 & ncf == 1
   if mtype == 'syst'
     [a,b,c,d] = unpck(sys);
     c(outputs,:) = fac*c(outputs,:);
     d(outputs,:) = fac*d(outputs,:);
     newsys = pck(a,b,c,d);
   elseif mtype == 'cons'
     newsys = sys;
     newsys(outputs,:) = fac*sys(outputs,:);
   elseif mtype == 'empt';
     newsys = [];
   else
     [vd,rp,indv] = vunpck(sys);
     newsys = sys;
     tmp = reshape(vd,mrows,mnum*mcols);
     tmp(outputs,:) = fac*tmp(outputs,:);
     newsys(1:mrows*mnum,1:mcols) = reshape(tmp,mrows*mnum,mcols);
%     mat1 = ones(mrows,1);
%     mat1(outputs) = fac*mat1(outputs);
%     tmp = diag(mat1) * reshape(vd,mrows,mnum*mcols);
%     newsys = vpck(reshape(tmp,mrows*mnum,mcols),indv);
   end
 else
   error('fac should be a scalar')
   return
 end
%
% Copyright MUSYN INC 1991,  All Rights Reserved
