Path: news.mathworks.com!not-for-mail
From: "Ulrik Nash" <uwn@sam.sdu.dk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Randomizing column vector and keeping associated numbers in other
Date: Wed, 9 May 2012 10:24:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 53
Message-ID: <jodgk9$846$1@newscl01ah.mathworks.com>
References: <jodd5j$oph$1@newscl01ah.mathworks.com> <jodesn$ihg$1@speranza.aioe.org>
Reply-To: "Ulrik Nash" <uwn@sam.sdu.dk>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1336559049 8326 172.30.248.46 (9 May 2012 10:24:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 9 May 2012 10:24:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2106050
Xref: news.mathworks.com comp.soft-sys.matlab:767292

"Nasser M. Abbasi" <nma@12000.org> wrote in message <jodesn$ihg$1@speranza.aioe.org>...
> On 5/9/2012 4:25 AM, Ulrik Nash wrote:
> > Hi Everyone,
> >
> > I have a matrix with two columns, and which might potentially hold
> >  many rows (>1000).
> >
> > What is the most efficient way to randomize the numbers in the first column,
> >while keeping the associated value in the second columns? I am thinking about
> >randperm, but as far as I can see it only allows the randomization of one
> >vector at the time, thus disregarding the associated numbers in other columns...
> 
> help rand()
> 
> --------------------------------------
> EDU>> A=[1 78  79  80;
>           2 101 103 104
>        ];
> 
> A(:,1)=rand(2,1)
> A(:,1)=rand(2,1)
> A(:,1)=rand(2,1)
> --------------------------------
> 
> A =
>      0.2785   78.0000   79.0000   80.0000
>      0.5469  101.0000  103.0000  104.0000
> 
> A =
>      0.9575   78.0000   79.0000   80.0000
>      0.9649  101.0000  103.0000  104.0000
> 
> 
> A =
>      0.1576   78.0000   79.0000   80.0000
>      0.9706  101.0000  103.0000  104.0000
> 
> ---------------------------------------------
> 
> --Nasser


Thanks Nasser, but it is not quite what I am after. I think perhaps I should be more specific.

Suppose I have the following matrix:

A = [1 10;2 20;3 30]

What I wish to achieve is randomizing the order of the first columns numbers (ie the 1, 2 and 3), while keeping the associated numbers in columns two. For example:

B = [2 20;1 10; 3 30]

I hope I am clearer now.