Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!newsfeed.cwix.com!dc3peer2.nntp.savvis.net!peer.nntp.savvis.net!bigfeed.bellsouth.net!news.bellsouth.net!cyclone1.gnilink.net!gnilink.net!nx01.iad.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe06.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Do stuff without colons
References: <ghmkpn$9ml$1@fred.mathworks.com> <ghml3n$eoe$1@fred.mathworks.com>
In-Reply-To: <ghml3n$eoe$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 25
Message-ID: <GOA%k.20730$b05.17915@newsfe06.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe06.iad 1228855590 24.79.146.116 (Tue, 09 Dec 2008 20:46:30 UTC)
NNTP-Posting-Date: Tue, 09 Dec 2008 20:46:30 UTC
Date: Tue, 09 Dec 2008 14:46:42 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:505949


Matt wrote:
> "Pithawat " <tanvach+matlab@gmail.com> wrote in message <ghmkpn$9ml$1@fred.mathworks.com>...

>> a = randperm(100);
>> b = a(1:10); % Choose only first 10 random permutations

>> Is it possible to combine these two lines into one:

> b=ceil(100*rand(1,10));

That's not equivalent!! randperm is selection without replacement; rand() is selection
-with- replacement.
 
firstN = @(v,n) v(1:N);
a = firstN(randperm(100),10);

OR, using only built-in functions,

subsref(randperm(100),struct('type','()','subs',{{1:10}}))

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?