Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Curious
Posts:
1,992
Registered:
12/6/04


Re: sorting, ranking
Posted:
Aug 21, 2009 12:50 PM


"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.)



