Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
random shufflling

Subject: random shufflling

From: SHIBU A

Date: 7 Jan, 2011 17:35:04

Message: 1 of 4

I want to shuffle the elements of a matrix in row wise (i.e., not the entire row together) by placing the elemnets randomly, but not to change the column wise (i.e., sum of the column elements should be the same before and after shuffling, but can change the rows). Can anybody please help me in coding. Any command is available.
Eg:-A=[1 0 0 0 0 0
           0 1 0 0 0 0
           0 0 1 0 0 0
           0 0 0 1 0 0
           0 0 0 0 1 0
           0 0 0 0 0 1 ]
After shuffling may be some what like this,
     B= [0 0 1 0 0 0
           0 1 0 0 0 0
           0 0 0 1 0 0
           1 0 0 0 0 0
           0 0 0 0 0 1
           0 0 0 0 1 0 ]
I would like to generate matrix of size F*NDx NP* ND, where F=1, ---,5. and NP=1,....10. Here, ND =6. Iin each row, from column 1 to 6 , 7 to 12, 13 to 18, ----, only one one can be placed.

Thanks in advance---
Kind regards,
Shibu

Subject: random shufflling

From: Sean de

Date: 7 Jan, 2011 18:14:05

Message: 2 of 4

"SHIBU A" wrote in message <ig7is8$1um$1@fred.mathworks.com>...
> I want to shuffle the elements of a matrix in row wise (i.e., not the entire row together) by placing the elemnets randomly, but not to change the column wise (i.e., sum of the column elements should be the same before and after shuffling, but can change the rows). Can anybody please help me in coding. Any command is available.
> Eg:-A=[1 0 0 0 0 0
> 0 1 0 0 0 0
> 0 0 1 0 0 0
> 0 0 0 1 0 0
> 0 0 0 0 1 0
> 0 0 0 0 0 1 ]
> After shuffling may be some what like this,
> B= [0 0 1 0 0 0
> 0 1 0 0 0 0
> 0 0 0 1 0 0
> 1 0 0 0 0 0
> 0 0 0 0 0 1
> 0 0 0 0 1 0 ]

One way would be with a FOR-loop:
%%%
A = eye(10);
for ii = 1:size(A,2);
    A(:,ii) = A(randperm(size(A,1)),ii);
end
%%%
Expand upon it as you need

Subject: random shufflling

From: Jos (10584)

Date: 7 Jan, 2011 21:09:04

Message: 3 of 4

"SHIBU A" wrote in message <ig7is8$1um$1@fred.mathworks.com>...
> I want to shuffle the elements of a matrix in row wise (i.e., not the entire row together) by placing the elemnets randomly, but not to change the column wise (i.e., sum of the column elements should be the same before and after shuffling, but can change the rows). Can anybody please help me in coding. Any command is available.
> Eg:-A=[1 0 0 0 0 0
> 0 1 0 0 0 0
> 0 0 1 0 0 0
> 0 0 0 1 0 0
> 0 0 0 0 1 0
> 0 0 0 0 0 1 ]
> After shuffling may be some what like this,
> B= [0 0 1 0 0 0
> 0 1 0 0 0 0
> 0 0 0 1 0 0
> 1 0 0 0 0 0
> 0 0 0 0 0 1
> 0 0 0 0 1 0 ]
> I would like to generate matrix of size F*NDx NP* ND, where F=1, ---,5. and NP=1,....10. Here, ND =6. Iin each row, from column 1 to 6 , 7 to 12, 13 to 18, ----, only one one can be placed.
>
> Thanks in advance---
> Kind regards,
> Shibu

The functions RANDSWAP and SHAKE do exactly this:
http://www.mathworks.com/matlabcentral/fileexchange/12621-randswap
http://www.mathworks.com/matlabcentral/fileexchange/10067-shake

hth
Jos

Subject: random shufflling

From: Jan Simon

Date: 7 Jan, 2011 23:30:07

Message: 4 of 4

Dear SHIBU,

> I want to shuffle the elements of a matrix in row wise...

You can specify the dimension to operate on in Shuffle also:
  http://www.mathworks.com/matlabcentral/fileexchange/27076

Kind regards, Jan

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us