home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / sysreorder.m < prev    next >
Text File  |  1999-03-05  |  2KB  |  53 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function pv = sysreorder(vlen,list)
  18. # function pv = sysreorder(vlen,list)
  19. #
  20. # inputs: vlen: vector length
  21. #         list: a subset of {1:vlen}
  22. # pv: a permutation vector to order elements of [1:vlen] in -list-
  23. #         to the end of a vector
  24. # used internally by sysconnect to permute vector elements to their
  25. # desired locations.  No user-serviceable parts inside; do not attempt
  26. # to use this at home!
  27.  
  28. # A. S. Hodel, Aug 1995
  29.   
  30.   #disp('sysreorder: entry')
  31.   
  32.   pv = 1:vlen;
  33.   # make it a row vector
  34.   list = reshape(list,1,length(list));
  35.   A = pv'*ones(size(list));
  36.   B = ones(size(pv'))*list;
  37.   X = (A != B);
  38.   if(!is_vector(X))
  39.     y = min(X');
  40.   else
  41.    y = X';
  42.   endif
  43.   z = find(y == 1);
  44.   if(!isempty(z))
  45.     pv = [z, list];
  46.   else
  47.     pv = list;
  48.   endif
  49.   
  50. endfunction
  51.