home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS1.DI$ / VDIAG.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.2 KB  |  46 lines

  1. % function out = vdiag(matin)
  2. %
  3. %   Diagonal of a VARYING matrix. Operates just as DIAG
  4. %   does in standard MATLAB, but on VARYING matrices also.
  5. %
  6. %   See also: DIAG, VEBE, and VEVAL.
  7.  
  8. function out = vdiag(matin)
  9.  if nargin == 0
  10.    disp('usage: out = vdiag(matin)');
  11.    return
  12.  end
  13.  [mtype,mrows,mcols,mnum] = minfo(matin);
  14.  if mtype == 'cons'
  15.    out = diag(matin);
  16.  elseif mtype == 'vary'
  17.    if mrows == 1         % out is mcols x mcols
  18.      nrout = mcols;
  19.      ncout = mcols;
  20.    elseif mcols == 1     % out is mrows x mrows
  21.      nrout = mrows;
  22.      ncout = mrows;
  23.    else                  % out is min([mrows mcols]) x 1
  24.      nrout = min([mrows mcols]);
  25.      ncout = 1;
  26.    end
  27.    out = zeros((mnum*nrout)+1,ncout+1);
  28.    npts = mnum;
  29.    ff = (npts+1)*mrows;
  30.    pt = 1:mrows:ff;
  31.    ptm1 = pt(2:npts+1)-1;
  32.    for i=1:npts
  33.      out((nrout*(i-1)+1):nrout*i,1:ncout) = diag(matin(pt(i):ptm1(i),1:mcols));
  34.    end
  35.    out(1:npts,ncout+1) = matin(1:npts,mcols+1);
  36.    out((mnum*nrout)+1,ncout) = npts;
  37.    out((mnum*nrout)+1,ncout+1) = inf;
  38.  elseif mtype == 'syst'
  39.    error('VDIAG is undefined for SYSTEM matrices');
  40.    return
  41.  else
  42.    out = [];
  43.  end
  44. %
  45. % Copyright MUSYN INC 1991,  All Rights Reserved
  46.