Search this blog!

Friday, February 24, 2012

In Matlab : Sorting by indexes of another sorting

Imagine, we have the following two array of numbers
A=[ 2 4 6 7 8 8];
 B=[ 5 8 2 5 0 5];
Problem:
---------
we want to sort A and then arrange B according to the index of A.

Solution:
----------

>> [sortedA,indexA]=sort(A)

sortedA =

     2     4     6     7     8     8

indexA =

     1     2     3     4     5     6



>> B(indexA)

ans =

     5     8     2     5     0     5

No comments:

Post a Comment