Shuffle values along a particular dimension of an array.
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.
y The shuffled array.

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 .
>>a=[20 30 40;2 3 4; 50,2,70];
          2          2          4
         20          3         40
         50         30         70

        200        300        400
         20         30         40
        500         20        700

         20         20         40
        200         30        400
        500        300        700