Prev: Remapping a Matrix.
Next: Vectorization help
From: james bejon on 31 Mar 2010 05:46 I know this is a really old thread, but could someone please explain to me how Bruno's solution works? I can't see how it arrives at the correct answer. Thanks, James.
From: Bruno Luong on 31 Mar 2010 07:13 "james bejon" <jamesbejon(a)yahoo.co.uk> wrote in message <hov5ks$2lj$1(a)fred.mathworks.com>... > I know this is a really old thread, but could someone please explain to me how Bruno's solution works? I can't see how it arrives at the correct answer. > > Thanks, James. For *vector* "a", the second output of the command [s i] = SORT(a) satisfies (see doc) s = a(i) where s is sorted, (eqt1). Ranking 'r' is by definition a permutation such that s(r) = a, (eqt2). From (eqt1 & 2) we get: s(r(i)) = a(i) = s = s(1:length(s)) Therefore by comparing the indexes of the most lhs and the most rhs of the equality we have: r(i) = 1:length(s) (in other word, r and i are mutually inverse permutations) Now if you apply the above for 'a' successively is the row vector of the array A(k,:) k=1,2,.... you 'll find the logic behind my code. The confusing thing in the code is that I use the same array named 'i' (for 'r') in the latest statement to limit reuse the same memory. But I hope you get the logic of the code. Bruno
From: james bejon on 31 Mar 2010 14:18 I've read (and stepped) through this code a few times now. And I think I get it. Very nice move.
|
Pages: 1 Prev: Remapping a Matrix. Next: Vectorization help |