Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: randperm
Date: Sun, 18 Apr 2010 20:08:21 +0000 (UTC)
Organization: Univ of Sussex
Lines: 9
Message-ID: <hqforl$jis$1@fred.mathworks.com>
References: <hqfo0t$71n$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1271621301 20060 172.30.248.38 (18 Apr 2010 20:08:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 18 Apr 2010 20:08:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 415894
Xref: news.mathworks.com comp.soft-sys.matlab:627676

randperm is the right tool - but maybe you aren't using it the way you need to. The following code does what I think you want:

x=[12 1 9 6 87 43 11 98];
y=[32 44 4 5 6 7 14 11];
needed = 4;
ind = randperm(length(x));
selected = ind(1:needed);
xselected = x(selected)
yselected = y(selected)