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

  1. % function [out,err] = sortiv(in,sortflg,nored,epp)
  2. %
  3. %   If the INDEPENDENT VARIABLE is not monotonically increasing, 
  4. %   then the INDEPENDENT VARIABLE is reordered accordingly and 
  5. %   return to OUT. SORTFLG = 0 (default) sorts the INDEPENDENT 
  6. %   VARIABLE in increasing order and SORTFLG = 1 sorts in 
  7. %   decreasing order. NORED = 0 (default) does not
  8. %   reduce the number of INDEPENDENT VARIABLEs even if there
  9. %   are repeated ones. Setting NORED to a nonzero value causes
  10. %   repeated INDEPENDENT VARIABLEs to be collapsed down if
  11. %   their corresponding matrices are the same, if they are
  12. %   not an error message is displayed and only the first
  13. %   INDEPENDENT VARIABLE and corresponding matrix is kept.
  14. %   The output argument ERR which is nominally 0, is set to 1
  15. %   if an error message is displayed. EPP is used to test for 
  16. %   closeness of two INDEPENDENT VARIABLEs and the matrices 
  17. %   associated them. Its default values is [1e-9; 1e-9]. SORTIV 
  18. %   can be used with TACKON to mesh together frequency responses
  19. %   or time responses. 
  20. %
  21. %   See also: GETIV, INDVCMP, SORT, TACKON, XTRACT, and XTRACTI.
  22.  
  23.  
  24. function [out,err] = sortiv(in,sortflg,nored,epp)
  25.  if nargin < 1
  26.    disp('usage: [out,err] = sortiv(in,sortflg,nored,epp)');
  27.    return
  28.  end
  29.  if nargin == 1
  30.    sortflg = 0;
  31.    nored = 0;
  32.    epp = [1e-9; 1e-9];
  33.  end
  34.  if nargin == 2
  35.    nored = 0;
  36.    epp = [1e-9; 1e-9];
  37.  end
  38.  if nargin == 3
  39.    epp = [1e-9; 1e-9];
  40.  end
  41.  [mtype,mrows,mcols,mnum] = minfo(in);
  42.  if mtype == 'cons'
  43.    out = in;
  44.  elseif mtype == 'vary'
  45.    ivin = in(1:mnum,mcols+1);
  46.    [ivout,ind] = sort(ivin);
  47.    if sortflg ~= 0
  48.      ivout = flipud(ivout);
  49.      ind = flipud(ind);
  50.    end
  51.    out = [];
  52.    ivcnt = [];
  53.    err = 0;
  54.  if nored ~= 0
  55.    for i=1:mnum
  56.      if i > 1
  57.        if abs(ivout(i)-ivout(i-1)) < epp(1,1)
  58.          tmp1 = in((ind(i)-1)*mrows+1:ind(i)*mrows,1:mcols);
  59.          tmp2 = in((ind(i-1)-1)*mrows+1:ind(i-1)*mrows,1:mcols);
  60.          if norm(abs(tmp1-tmp2)) > epp(2,1)
  61.            if err ~= 1
  62.              disp(' two iv''s have the same value but different matrices')
  63.          err = 1;
  64.            end
  65.      end
  66.        else
  67.      j = j + 1;
  68.          ivcnt(j) = ivout(i);
  69.          out = [out ; in((ind(i)-1)*mrows+1:ind(i)*mrows,1:mcols)];
  70.        end
  71.      else
  72.        ivcnt(1) = ivout(1);
  73.        out = [out ; in((ind(i)-1)*mrows+1:ind(i)*mrows,1:mcols)];
  74.        j = 1;
  75.      end
  76.    end
  77.  else
  78.    for i=1:mnum
  79.      ivcnt(i) = ivout(i);
  80.      out = [out ; in((ind(i)-1)*mrows+1:ind(i)*mrows,1:mcols)];
  81.    end
  82.  end
  83.    out = vpck(out,ivcnt);
  84.  elseif mtype == 'syst'
  85.    disp('SORTIV not defined for SYSTEM matrices')
  86.    return
  87.  else
  88.    out = [];
  89.  end
  90. %
  91. % Copyright MUSYN INC 1991,  All Rights Reserved
  92.