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

  1. % function [matout,ivval] = var2con(mat,desiv)
  2. %
  3. %   VARYING to CONSTANT matrix conversion. If there is
  4. %   one input argument, MAT, and it is a VARYING matrix, then
  5. %   the output MATOUT is the CONSTANT matrix in MAT associated
  6. %   with the INDEPENDENT VARIABLE's first value. The optional
  7. %   second output argument is this INDEPENDENT VARIABLE's value.
  8. %   If two input arguments are used, then it is assumed that
  9. %   the first is a VARYING matrix, and the second is a
  10. %   desired INDEPENDENT VARIABLE's value. The command
  11. %   finds the matrix in MAT whose INDEPENDENT VARIABLE's
  12. %   value is closest to DESIV, and returns this matrix
  13. %   as a CONSTANT matrix. 
  14. %
  15. %   See also: XTRACT and XTRACTI.
  16.  
  17. function [matout,ivval] = var2con(mat,desiv)
  18.   if nargin < 1
  19.     disp('usage: [matout,ivval] = var2con(mat,desiv)')
  20.     return
  21.   end
  22.   [mtype,mrows,mcols,mnum] = minfo(mat);
  23.   if mtype == 'vary'
  24.     indv = mat(1:mnum,mcols+1);
  25.     if nargin == 2
  26.       [val,loc] = min(abs(indv-desiv*ones(mnum,1)));
  27.       matout = mat((loc-1)*mrows+1:mrows*loc,1:mcols);
  28.       ivval = mat(loc,mcols+1);
  29.     else
  30.       matout = mat(1:mrows,1:mcols);
  31.       ivval = mat(1,mcols+1);
  32.     end
  33.   elseif mtype == 'cons'
  34.     matout = mat;
  35.     ivval = [];
  36.   elseif mtype == 'syst'
  37.     error(['input is not a valid VARYING matrix'])
  38.     return
  39.   end
  40. %
  41. % Copyright MUSYN INC 1991,  All Rights Reserved
  42.