Random order of the rows in a matrix

  • Follow


Hi all members of Google groups
  I have a small question like this. I have a 2-Dimensional matrix. And
I need a method to manipulate a 2-D matrix such that the row order can
be in random arrangements.

0
Reply hoangtrongminhtuan (17) 11/11/2006 11:15:44 AM

Hoang Trong Minh Tuan skrev:
> Hi all members of Google groups
>   I have a small question like this. I have a 2-Dimensional matrix. And
> I need a method to manipulate a 2-D matrix such that the row order can
> be in random arrangements.

First we create a test matrix:

X = magic(5)

of size:

[numRows, numCols] = size(X);

The goal is to randomly shuffle the rows of this matrix. For this we
can use the randperm function which creates a random permutation of
integers from 1 to its input argument n

indices = randperm(numRows);

So the shuffeled matrix is obtained as:

Y = X(indices, :)

0
Reply jogerh2032 (17) 11/11/2006 11:25:32 AM


Hoang Trong Minh Tuan wrote:
>
>
> Hi all members of Google groups
> I have a small question like this. I have a 2-Dimensional matrix.
> And
> I need a method to manipulate a 2-D matrix such that the row order
> can
> be in random arrangements.
>
>

Look for SHAKE or RANDSWAP on the File Exchange.

hth
Jos
0
Reply Jos 11/11/2006 2:14:58 PM

2 Replies
33 Views

(page loaded in 0.052 seconds)


Reply: