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

  1. % function out = sel(mat,rowdata,coldata)
  2. %
  3. %   selects rows and columns from a VARYING matrix
  4. %   and outputs and inputs from a SYSTEM matrix.
  5. %
  6. %   See also: GETIV, REORDSYS, SRESID, TRUNC, UNPCK, 
  7. %             VUNPCK, XTRACT and XTRACTI.
  8.  
  9. function [out] = sel(mat,rdata,cdata)
  10.  if nargin ~= 3
  11.    disp('usage: out = sel(mat,rowdata,coldata)')
  12.    return
  13.  end
  14.  if min(size(rdata)) ~= 1 | min(size(cdata)) ~= 1
  15.    error('ROWDATA and COLDATA should be vectors')
  16.    return
  17.  end 
  18.  [nr,nc] = size(mat);
  19.  [mtype,mrows,mcols,mnum] = minfo(mat);
  20.  if mtype == 'vary'
  21.    if max(cdata) <= mcols & min(cdata) > 0 ...
  22.      & max(rdata) <= mrows & min(rdata) > 0
  23.      npts = mnum;
  24.      nrout = max(size(rdata));
  25.      ncout = max(size(cdata));
  26.      out = zeros(nrout*npts+1,ncout+1);
  27.      out(nrout*npts+1,ncout+1) = inf;
  28.      out(nrout*npts+1,ncout) = npts;
  29.      out(1:npts,ncout+1) = mat(1:mnum,nc);
  30.      ff = (npts+1)*mrows;
  31.      fout = (npts+1)*nrout;
  32.      pp = 1:mrows:ff;
  33.      pout = 1:nrout:fout;
  34.      ppm1 = pp(2:npts+1) - 1;
  35.      poutm1 = pout(2:npts+1) - 1; 
  36.      for i=1:npts
  37.        out(pout(i):poutm1(i),1:ncout) = mat((pp(i)-1)+rdata,cdata);
  38.      end
  39.    else
  40.      error('column or row data out of range')
  41.      return
  42.    end
  43.  elseif mtype == 'syst'
  44.    if max(cdata) <= mcols & min(cdata) > 0 ...
  45.      & max(rdata) <= mrows & min(rdata) > 0
  46.      cols = [1:mnum mnum+cdata nc];
  47.      rows = [1:mnum mnum+rdata nr];
  48.      out = mat(rows,cols);
  49.    else
  50.      error('input or output data out of range')
  51.      return
  52.    end
  53.  elseif mtype == 'cons'
  54.    if max(cdata) <= mcols & min(cdata) > 0 ...
  55.       & max(rdata) <= mrows & min(rdata) > 0
  56.      out = mat(rdata,cdata);
  57.    else
  58.      error('column or row data out of range')
  59.      return
  60.    end
  61.  else
  62.    out = [];
  63.  end
  64. %
  65. % Copyright MUSYN INC 1991,  All Rights Reserved
  66.