Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: sorting, ranking
Replies: 10   Last Post: Jan 14, 2013 1:25 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Spider

Posts: 23
Registered: 12/7/04
sorting, ranking
Posted: Aug 21, 2009 12:16 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.