Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: sorting, ranking Date: Fri, 21 Aug 2009 16:16:03 +0000 (UTC) Organization: Indiana University Lines: 64 Message-ID: <h6mh83$j42$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1250871363 19586 172.30.248.35 (21 Aug 2009 16:16:03 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 21 Aug 2009 16:16:03 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 406168 Xref: news.mathworks.com comp.soft-sys.matlab:565109 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