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

ranksort

(tmp_for_tar/misc/ranksort.m)


Function Synopsis

r = ranksort(v)

Help text

       r = ranksort(v)

 r(i) is the rank of v(i), starting at one. That is, the number of
 distinct values that occur in  v  and are smaller or equal to v(i)

 r  has same size as  v

 Warning : Memory cost is quadratic in the number of elements of v

 Last modified: April 2001



Listing of function file tmp_for_tar/misc/ranksort.m

##       r = ranksort(v)
## 
## r(i) is the rank of v(i), starting at one. That is, the number of
## distinct values that occur in  v  and are smaller or equal to v(i)
## 
## r  has same size as  v
## 
## Warning : Memory cost is quadratic in the number of elements of v

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

function r = ranksort(v)

[R,C]=size(v) ;
N = R*C ;
if N==0, r = zeros(R,C) ; return ; end

v = v(:);
r = sum( v*ones(1,N) <= ones(N,1)*v' ) ;
tmp = zeros(1,N) ;
tmp(r) = 1 ;
tmp(find(tmp)) = 1:sum(tmp) ;
r = tmp(r) ;
r = reshape(r,R,C) ;
## other version of the algorithm
#  [w,p] = sort(v) ;
#  [x,q] = uniq(w) ;

#  r = zeros(1,N+1) ;
#  r(q+1) = 1 ;
#  r = 1 + cumsum(r(1:N)) ;
#  r = r * eye(N)(p,:) ;		# Apply inverse permutation to r

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