shuffle
Shuffle values along a particular dimension of an array.
y=shuffle(a,ind,dim)
Inputs
a Any array.
ind An array of integers of the same size as a . The elements of the array must be positive integers ranging up to the size of the array along the dimension specified by the last input.
dim The dimension along which the elements are to be shuffled.
Outputs
y The shuffled array.


Description
ind is typically the second output of the function sort or sortnd . The result is such that with M=ind[i,j,...,:, p,q,..] , the vector y[i,j,k,..,:, p,q,..] is identical to the vector a[i,j,k,..,M, p,q,..] .

This function may be used to reorder arrays of the same size according to the ordering specified by sorting on one of the arrays. For example, if a and b are two matrices of the same size, and (y,ind)=sort(a) , the expression shuffle(b,ind,1) leads to the same ordering of the elements of the columns of b as in y, which is obtained by sorting the columns of a .
Example
>>a=[20 30 40;2 3 4; 50,2,70];
>>b=a*10
>>(as,ind)=sort(a)
>>as
          2          2          4
         20          3         40
         50         30         70

>>b
        200        300        400
         20         30         40
        500         20        700

>>shuffle(b,ind,1)
         20         20         40
        200         30        400
        500        300        700