[Y,index] = Shuffle(X [, bindDim])
Randomly sorts X.
If X is a vector, sorts all of X, so Y = X(index).
If X is an m-by-n matrix, sorts each column of X, so
for j=1:n, Y(:,j)=X(index(:,j),j).
The optional ‘bindDim’ parameter allows this function to shuffle with the
same order across the bindDim. It also work with higher dimension arrays.
for example, if you have an n by m matrix X and hope shuffle each column
with same random order (Shuffle the rows), rather than shuffle each
column independently, you can run Shuffle(X, 2). This function also works
on higher dimension arrays. say a 3-d array, If you bind the 2nd
dimension, it will shuffle the rows on each page independently. If I bind
the 2nd and 3rd dimension, then it will shuffle the layer of the 3-d
create a 2-d array:
x = repmat((1:4)’,1,5)
Create a 3-d array (4 by 5 by 3), each column contains a vector [1:4]’
x = reshape(repmat(reshape(kron([1,1,1],1:4),4,3),5,1),4,5,3)
Create a 3-d array (3 by 4 by 5), each row contains a vector [1:4]
x = reshape(repmat(reshape(kron(1:4,[1,1,1]),3,4),1,5),3,4,5)