[Index for tmp_for_tar/misc] [Return to Master Index]

lexicosort

(tmp_for_tar/misc/lexicosort.m)


Function Synopsis

[vv,ii] = lexicosort (v)

Help text

       [vv,ii] = lexicosort (v) - Sort lexicographically the rows of v

 Sort lexicographicaly the rows of matrix v. Works for integer and
 real-valued data.

 v  : R x C : Data to be sorted

 vv : R x C : Sorted data
 ii : R x 1 : Sorted indices : v(ii,:) == vv.

 Last modified: April 2001



Listing of function file tmp_for_tar/misc/lexicosort.m

##       [vv,ii] = lexicosort (v) - Sort lexicographically the rows of v
##
## Sort lexicographicaly the rows of matrix v. Works for integer and
## real-valued data.
##
## v  : R x C : Data to be sorted
##
## vv : R x C : Sorted data
## ii : R x 1 : Sorted indices : v(ii,:) == vv.
##

## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: April 2001

function [vv,ii] = lexicosort (v)

  [R,C] = size (v);
  if C<=1,			# Single column
    [vv,ii] = sort (v);
    return
  elseif R <= 1,		# Single row (apparently, no need to treat
				# as a special case)
    vv = v ;
    ii = 1 ;
    return
  end
				# Recognize the code from sortrows()? (by
				# Daniel Calvelo, then Paul Kienzle)
  ii = [1:R]' ;
  for i = C:-1:1;
    [dum,idx] = sort (v(ii,i)); # sort keeps the original order :)
    ii = ii(idx);
  end
  vv = v(ii,:);
  return
endfunction

Produced by oct2html on Sat Apr 28 21:14:54 2001
Cross-Directory links are: ON