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:
shuffling a row

Subject: shuffling a row

From: Syed Imam

Date: 7 Nov, 2012 17:06:08

Message: 1 of 8

i want a MATLAB code to shuffle a row

>> A= [1 2 3 4 5];

what command should i use to get a result [3 1 5 4 2]

after that what command should i use to re-shuffle again to get a result
 like this [ 1 2 3 4 5]

please help me

Subject: shuffling a row

From: dpb

Date: 7 Nov, 2012 18:49:12

Message: 2 of 8

On 11/7/2012 11:06 AM, Syed Imam wrote:
> i want a MATLAB code to shuffle a row
>
>>> A= [1 2 3 4 5];
>
> what command should i use to get a result [3 1 5 4 2]

All depends. By what rule was the result derived?

If it's just a permutation,

doc randperm

> after that what command should i use to re-shuffle again to get a result
> like this [ 1 2 3 4 5]

Again all depends but basically the inverse of the previous permutation
(which may be simply keeping the order vector)

--

Subject: shuffling a row

From: Syed Imam

Date: 7 Nov, 2012 22:26:13

Message: 3 of 8

dpb <none@non.net> wrote in message <k7eac3$s0$1@speranza.aioe.org>...
> On 11/7/2012 11:06 AM, Syed Imam wrote:
> > i want a MATLAB code to shuffle a row
> >
> >>> A= [1 2 3 4 5];
> >
> > what command should i use to get a result [3 1 5 4 2]
>
> All depends. By what rule was the result derived?
>
> If it's just a permutation,
>
> doc randperm
>
> > after that what command should i use to re-shuffle again to get a result
> > like this [ 1 2 3 4 5]
>
> Again all depends but basically the inverse of the previous permutation
> (which may be simply keeping the order vector)
>
> --


BASICALLY ITS A SIMPLE ROW DERIVATION

IT CAN BE DERIVE IN TWO WAYS
1ST WAY >> A = (1:5);
2ND WAY >> A = [1 2 3 4 5]

IT DOESN'T ,MATTER

i want the code to shuffle the row and then re-shuffle to get back the same result
please please reply ASAP

please write the proper MATLAB commands as it will be a great great help

Subject: shuffling a row

From: dpb

Date: 7 Nov, 2012 23:00:33

Message: 4 of 8

On 11/7/2012 4:26 PM, Syed Imam wrote:
> dpb <none@non.net> wrote in message <k7eac3$s0$1@speranza.aioe.org>...
>> On 11/7/2012 11:06 AM, Syed Imam wrote:
>> > i want a MATLAB code to shuffle a row
>> >
>> >>> A= [1 2 3 4 5];
>> >
>> > what command should i use to get a result [3 1 5 4 2]
>>
>> All depends. By what rule was the result derived?
>>
>> If it's just a permutation,
>>
>> doc randperm
>>
>> > after that what command should i use to re-shuffle again to get a
>> result
>> > like this [ 1 2 3 4 5]
>>
>> Again all depends but basically the inverse of the previous
>> permutation (which may be simply keeping the order vector)
>>

> BASICALLY ITS A SIMPLE ROW DERIVATION
>
> IT CAN BE DERIVE IN TWO WAYS
> 1ST WAY >> A = (1:5);
> 2ND WAY >> A = [1 2 3 4 5]

Well, yes, that's obvious. It doesn't explain how you arrived at the
result of [3 1 5 4 2], however, which was/is the question.

> IT DOESN'T ,MATTER

Well, if that is the answer to the question, then the answer is

doc randperm % as given earlier

> i want the code to shuffle the row and then re-shuffle to get back the
> same result

doc sort % will be of some use here--NB the second optional argument
          % and be sure to note the previous hint of the order vector
          % of the original permutation hanging around is important...

> please please reply ASAP

Chill, dood...

> please write the proper MATLAB commands as it will be a great great help

Please read the documentation and hints and work on it yourself--post
your efforts.

--

Subject: shuffling a row

From: Syed Imam

Date: 8 Nov, 2012 08:24:07

Message: 5 of 8

>> A=(1:8)

A =

     1 2 3 4 5 6 7 8


% randomizing the data
>> A(randperm(8))

ans =

     8 3 6 7 5 1 2 4

my question is how to de-randomize data to get the result [1 2 3 4 5 6 7 8] same like A??

Subject: shuffling a row

From: Bruno Luong

Date: 8 Nov, 2012 12:40:09

Message: 6 of 8

"Syed Imam" <nasmc92@hotmail.co.uk> wrote in message <k7fq77$apn$1@newscl01ah.mathworks.com>...
> >> A=(1:8)
>
> A =
>
> 1 2 3 4 5 6 7 8
>
>
> % randomizing the data
> >> A(randperm(8))
>
> ans =
>
> 8 3 6 7 5 1 2 4
>
> my question is how to de-randomize data to get the result [1 2 3 4 5 6 7 8] same like A??

A=(1:8);
p = randperm(length(A))
B = A(p);

% first method
clear A1
A1(p) = B

% second method
clear q
q(p) = 1:length(p);
A2 = B(q)

% Bruno

Subject: shuffling a row

From: dpb

Date: 8 Nov, 2012 13:34:01

Message: 7 of 8

On 11/8/2012 6:40 AM, Bruno Luong wrote:
> "Syed Imam" <nasmc92@hotmail.co.uk> wrote in message
> <k7fq77$apn$1@newscl01ah.mathworks.com>...
>> >> A=(1:8)
>>
>> A =
>>
>> 1 2 3 4 5 6 7 8
>>
>>
>> % randomizing the data >> A(randperm(8))
>>
>> ans =
>>
>> 8 3 6 7 5 1 2 4
>>
>> my question is how to de-randomize data to get the result [1 2 3 4 5 6
>> 7 8] same like A??
>
> A=(1:8);
> p = randperm(length(A))
> B = A(p);
>
> % first method
> clear A1
> A1(p) = B
>
> % second method
> clear q
> q(p) = 1:length(p);
> A2 = B(q)
>

 > % third method
 > clear q
 > [~,ip]=sort(p);
 > A3 = B(ip);

--

Subject: shuffling a row

From: Syed Imam

Date: 8 Nov, 2012 14:37:11

Message: 8 of 8

dpb <none@non.net> wrote in message <k7gcaf$urv$1@speranza.aioe.org>...
> On 11/8/2012 6:40 AM, Bruno Luong wrote:
> > "Syed Imam" <nasmc92@hotmail.co.uk> wrote in message
> > <k7fq77$apn$1@newscl01ah.mathworks.com>...
> >> >> A=(1:8)
> >>
> >> A =
> >>
> >> 1 2 3 4 5 6 7 8
> >>
> >>
> >> % randomizing the data >> A(randperm(8))
> >>
> >> ans =
> >>
> >> 8 3 6 7 5 1 2 4
> >>
> >> my question is how to de-randomize data to get the result [1 2 3 4 5 6
> >> 7 8] same like A??
> >
> > A=(1:8);
> > p = randperm(length(A))
> > B = A(p);
> >
> > % first method
> > clear A1
> > A1(p) = B
> >
> > % second method
> > clear q
> > q(p) = 1:length(p);
> > A2 = B(q)
> >
>
> > % third method
> > clear q
> > [~,ip]=sort(p);
> > A3 = B(ip);
>
> --





CHEERS
thankyou

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