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:
how to shuffle rows of data stored in a variable?

Subject: how to shuffle rows of data stored in a variable?

From: aristotelis aristou

Date: 25 Apr, 2008 12:39:02

Message: 1 of 7

Hi
Is there any function that I can use to shuffle (randomly
sort) the rows (but not the columns) of data that I have
stored in a variable?
Example:

Taking these data

  1 2 3 4
1 A A A A
2 B B B B
3 C C C C
4 D D D D

and shuffling it to look like this

  1 2 3 4
3 C C C C
2 B B B B
4 D D D D
1 A A A A

I have found functions that sort data but I didn't find
anything that shuffles data.


thanks

Subject: how to shuffle rows of data stored in a variable?

From: Steven Lord

Date: 25 Apr, 2008 13:10:21

Message: 2 of 7


"aristotelis aristou" <aristo.telios@mathworks.com> wrote in message
news:fusjd6$ae4$1@fred.mathworks.com...
> Hi
> Is there any function that I can use to shuffle (randomly
> sort) the rows (but not the columns) of data that I have
> stored in a variable?
> Example:
>
> Taking these data
>
> 1 2 3 4
> 1 A A A A
> 2 B B B B
> 3 C C C C
> 4 D D D D
>
> and shuffling it to look like this
>
> 1 2 3 4
> 3 C C C C
> 2 B B B B
> 4 D D D D
> 1 A A A A
>
> I have found functions that sort data but I didn't find
> anything that shuffles data.
>
>
> thanks

n = 4;
A = magic(n)
ordering = randperm(n);
B = A(ordering, :)
C(ordering, :) = B
isTheShufflingReversible = isequal(A, C)

--
Steve Lord
slord@mathworks.com

Subject: how to shuffle rows of data stored in a variable?

From: david szotten

Date: 25 Apr, 2008 13:16:01

Message: 3 of 7

a = ['A' 'A' 'A' 'A';
'B' 'B' 'B' 'B';
'C' 'C' 'C' 'C';
'D' 'D' 'D' 'D'];

>> a(randperm(4),:)

ans =

CCCC
AAAA
BBBB
DDDD

regards,
david


"aristotelis aristou" <aristo.telios@mathworks.com> wrote in
message <fusjd6$ae4$1@fred.mathworks.com>...
> Hi
> Is there any function that I can use to shuffle (randomly
> sort) the rows (but not the columns) of data that I have
> stored in a variable?
> Example:
>
> Taking these data
>
> 1 2 3 4
> 1 A A A A
> 2 B B B B
> 3 C C C C
> 4 D D D D
>
> and shuffling it to look like this
>
> 1 2 3 4
> 3 C C C C
> 2 B B B B
> 4 D D D D
> 1 A A A A
>
> I have found functions that sort data but I didn't find
> anything that shuffles data.
>
>
> thanks

Subject: how to shuffle rows of data stored in a variable?

From: aristotelis aristou

Date: 25 Apr, 2008 13:53:01

Message: 4 of 7

"Steven Lord" <slord@mathworks.com> wrote in message
<fusl7t$8f7$1@fred.mathworks.com>...
>
> "aristotelis aristou" <aristo.telios@mathworks.com> wrote
in message
> news:fusjd6$ae4$1@fred.mathworks.com...
> > Hi
> > Is there any function that I can use to shuffle (randomly
> > sort) the rows (but not the columns) of data that I have
> > stored in a variable?
> > Example:
> >
> > Taking these data
> >
> > 1 2 3 4
> > 1 A A A A
> > 2 B B B B
> > 3 C C C C
> > 4 D D D D
> >
> > and shuffling it to look like this
> >
> > 1 2 3 4
> > 3 C C C C
> > 2 B B B B
> > 4 D D D D
> > 1 A A A A
> >
> > I have found functions that sort data but I didn't find
> > anything that shuffles data.
> >
> >
> > thanks
>
> n = 4;
> A = magic(n)
> ordering = randperm(n);
> B = A(ordering, :)
> C(ordering, :) = B
> isTheShufflingReversible = isequal(A, C)
>
> --
> Steve Lord
> slord@mathworks.com
>
>

great... thanks steve

Subject: how to shuffle rows of data stored in a variable?

From: aristotelis aristou

Date: 25 Apr, 2008 14:00:04

Message: 5 of 7

"david szotten" <szotten@hotmail.com> wrote in message
<fuslih$ms8$1@fred.mathworks.com>...
> a = ['A' 'A' 'A' 'A';
> 'B' 'B' 'B' 'B';
> 'C' 'C' 'C' 'C';
> 'D' 'D' 'D' 'D'];
>
> >> a(randperm(4),:)
>
> ans =
>
> CCCC
> AAAA
> BBBB
> DDDD
>
> regards,
> david

would that work for a large dataset?

Subject: how to shuffle rows of data stored in a variable?

From: Jos

Date: 28 Apr, 2008 07:50:04

Message: 6 of 7

"aristotelis aristou" <aristo.telios@mathworks.com> wrote
in message <fuso54$jvi$1@fred.mathworks.com>...
> "david szotten" <szotten@hotmail.com> wrote in message
> <fuslih$ms8$1@fred.mathworks.com>...
> > a = ['A' 'A' 'A' 'A';
> > 'B' 'B' 'B' 'B';
> > 'C' 'C' 'C' 'C';
> > 'D' 'D' 'D' 'D'];
> >
> > >> a(randperm(4),:)
> >
> > ans =
> >
> > CCCC
> > AAAA
> > BBBB
> > DDDD
> >
> > regards,
> > david
>
> would that work for a large dataset?


Take a look at my functions SHAKE and RANDSWAP on the File
exchange. SHAKE can permute each column or row or plane
(etc.) independently, RANDSWAP can permute rows, columns,
planes, etc.

In our case "randswap(a)" would do.

hth
Jos

The links (beware of line wraps):

http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=12621&objectType=FILE

http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=10067&objectType=FILE

Subject: how to shuffle rows of data stored in a variable?

From: aristotelis aristou

Date: 29 Apr, 2008 10:55:06

Message: 7 of 7

"Jos " <DELjos@jasenDEL.nl> wrote in message
<fv3vjc$7e8$1@fred.mathworks.com>...
> "aristotelis aristou" <aristo.telios@mathworks.com> wrote
> in message <fuso54$jvi$1@fred.mathworks.com>...
> > "david szotten" <szotten@hotmail.com> wrote in message
> > <fuslih$ms8$1@fred.mathworks.com>...
> > > a = ['A' 'A' 'A' 'A';
> > > 'B' 'B' 'B' 'B';
> > > 'C' 'C' 'C' 'C';
> > > 'D' 'D' 'D' 'D'];
> > >
> > > >> a(randperm(4),:)
> > >
> > > ans =
> > >
> > > CCCC
> > > AAAA
> > > BBBB
> > > DDDD
> > >
> > > regards,
> > > david
> >
> > would that work for a large dataset?
>
>
> Take a look at my functions SHAKE and RANDSWAP on the File
> exchange. SHAKE can permute each column or row or plane
> (etc.) independently, RANDSWAP can permute rows, columns,
> planes, etc.
>
> In our case "randswap(a)" would do.
>
> hth
> Jos
>
> The links (beware of line wraps):
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> .do?objectId=12621&objectType=FILE
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> .do?objectId=10067&objectType=FILE
>
>
>
thanks Jos, I 'll do that

Tags for 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