Path: news.mathworks.com!not-for-mail
From: "koji takahashi" <koji23@stanford.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: random sample of n rows from matrix
Date: Mon, 16 Jan 2012 19:40:08 +0000 (UTC)
Organization: Stanford University
Lines: 27
Message-ID: <jf1ueo$91h$1@newscl01ah.mathworks.com>
References: <hg5f9j$nrl$1@fred.mathworks.com> <imqe27$4nk$1@fred.mathworks.com>
Reply-To: "koji takahashi" <koji23@stanford.edu>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1326742808 9265 172.30.248.48 (16 Jan 2012 19:40:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 16 Jan 2012 19:40:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2415009
Xref: news.mathworks.com comp.soft-sys.matlab:754846

this is spot-on!  Thanks Hsing!
sample = m(randsample(1:length(m),n),:); % n = number of random selections


"Hsing " <umchang5@cc.umanitoba.ca> wrote in message <imqe27$4nk$1@fred.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <hg5f9j$nrl$1@fred.mathworks.com>...
> > I have the following code:
> > 
> > m = [1 23, 2 34, 3 45, 4 43]
> > 
> > Now I want to draw a random sample of n rows from m.
> > 
> > I have tried the following:
> > 
> > sample = m(randperm(n))
> > 
> > but I only get values from the first column.
> > 
> > What is the correct proceedure?
> 
> Suppose you have a matrix m of N rows and you would like to take a random sample of n rows from m, try
> 
> sample = m(randsample(1:N,n),:)
> randsample(1:N,n) gives you a sequence of n random integers from 1 to N.
> 
> Hsing
> 29.Mar.2011