Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Shuffle or randomize the data in the row
Date: Mon, 5 Nov 2012 20:12:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <k796iq$n4v$1@newscl01ah.mathworks.com>
References: <k78va9$n23$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1352146330 23711 172.30.248.37 (5 Nov 2012 20:12:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 5 Nov 2012 20:12:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:782096

"Syed Imam" <nasmc92@hotmail.co.uk> wrote in message <k78va9$n23$1@newscl01ah.mathworks.com>...
> generated data [ 1 2 3 4 5 ]
> shuffled data [ 3 5 1 2 4]... WHAT FUNCTION TO USE ?
> re-shuffled data [ 1 2 3 4 5] ... WHAT FUNCTION TO USE ?
- - - - - - - - -
  If by "shuffle" you actually mean a permutation in which each element should be replaced by a different element, that is called a "derangement".  A routine to generate random derangements can be obtained at the File Exchange:

 http://www.mathworks.com/matlabcentral/fileexchange/30189

 n = length(A);
 p = randpermfull(n);
 B = A(p);

To recover A from B, you need p:

 C = zeros(size(B));
 C(p) = B;

or if you actually need the inverse of p, do this:

 q = 1:n;
 q(p) = q;
 C = B(q);

  (It would be a lot easier to just save A.)

Roger Stafford