Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Reordering the top half of a Matrix
Date: Tue, 13 Nov 2012 07:24:16 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 16
Message-ID: <k7ssj0$i3b$1@newscl01ah.mathworks.com>
References: <k7segr$3d9$1@newscl01ah.mathworks.com> <k7sn6e$185$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1352791456 18539 172.30.248.45 (13 Nov 2012 07:24:16 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 Nov 2012 07:24:16 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:782666

"Roger Stafford" wrote in message <k7sn6e$185$1@newscl01ah.mathworks.com>...
>  [m,n] = size(A);
>  t = triu(reshape(1:m*n,m,n),1);
>  p = t(t>0);
>  q = p(randperm((2*n-min(m,n)-1)*min(m,n)/2));
>  A(p) = A(q);
> 
> Roger Stafford
- - - - - - - - - -
  A slightly simpler version:

 t = triu(reshape(1:numel(A),size(A)),1);
 p = t(t>0);
 A(p) = A(p(randperm(numel(p))));

Roger Stafford