Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sorting, ranking
Date: Fri, 21 Aug 2009 16:50:22 +0000 (UTC)
Organization: Mitre Corp
Lines: 69
Message-ID: <h6mj8e$s59$1@fred.mathworks.com>
References: <h6mh83$j42$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250873422 28841 172.30.248.38 (21 Aug 2009 16:50:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Aug 2009 16:50:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2318
Xref: news.mathworks.com comp.soft-sys.matlab:565120


"Wyatt " <hello@hello.com> wrote in message <h6mh83$j42$1@fred.mathworks.com>...
> Hello All,
> 
> I have encountered some weird behavior with matlab when attempting to rank a list of numbers.
> 
> lets assume that I generate a vector of random numbers.
> 
> K>>A = rand(1,10)*100
> 
> A =
> 
>   Columns 1 through 8
> 
>    79.2207   95.9492   65.5741    3.5712   84.9129   93.3993   67.8735   75.7740
> 
>   Columns 9 through 10
> 
>    74.3132   39.2227
> 
> 
> If I then sort these numbers
> 
> K>>[V,I] = sort(A)
> 
> V =
> 
>   Columns 1 through 8
> 
>     3.5712   39.2227   65.5741   67.8735   74.3132   75.7740   79.2207   84.9129
> 
>   Columns 9 through 10
> 
>    93.3993   95.9492
> 
> 
> I =
> 
>      4    10     3     7     9     8     1     5     6     2
> 
> 
> and wish to obtain their ranking
> 
> K>>temp = [1:10]
> 
> temp =
> 
>      1     2     3     4     5     6     7     8     9    10
> 
> 
> K>> rank = temp(I)
> 
> rank =
> 
>      4    10     3     7     9     8     1     5     6     2
> 
> 
> I should get back a permutation of the vector temp in terms of the ordered indices of sorted values from A, instead this code simply returns the I vector
> 
> the correct execution of the command rank = temp(I) should return 
> 
> rank = [7 10 3 1 8 9 4 6 5 2]
> 
> Am I missing something here, or mistaken about how matlab should behave in this case?  Or is there simply a bug?
> 
> thanks

Maybe I'm missing something here.
Why would you expect the above code NOT to return the I vector?
(I get the same result as you do above.)