Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Do stuff without colons
Date: Tue, 9 Dec 2008 20:49:02 +0000 (UTC)
Organization: Xoran Technologies
Lines: 32
Message-ID: <ghmlju$ndi$1@fred.mathworks.com>
References: <ghmkpn$9ml$1@fred.mathworks.com> <ghml3n$eoe$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228855742 23986 172.30.248.37 (9 Dec 2008 20:49:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Dec 2008 20:49:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:505950


"Matt" <mjacobson.removethis@xorantech.com> wrote in message <ghml3n$eoe$1@fred.mathworks.com>...
> "Pithawat " <tanvach+matlab@gmail.com> wrote in message <ghmkpn$9ml$1@fred.mathworks.com>...
> > Hello, I'd like to know if anyone can help me with this seemingly simple problem...
> > 
> > I want to know if it's possible to swap colon notation with a built in function. Let me give an example:
> > 
> > a = randperm(100);
> > b = a(1:10); % Choose only first 10 random permutations
> > 
> > Is it possible to combine these two lines into one:
> > 
> > b = function(randperm(100), 1:10);
> > 
> > or something along the line
> > 
> > b = randperm(100)(1:10);
> > 
> > This would really make my life so much easier!
> > 
> > Am I missing something here?
> > 
> > Pithawat
> 
> 
> b=ceil(100*rand(1,10));


Sorry, I realize now that this won't work. It samples 1:100 with replacement.

Is the idea here simply to save typing? If so, "someone"'s solution is a reasonable one.

Or, is the idea to cut down on the number of randomization operations you have to do? If the latter, you must be doing randperm(N) for very large N to make this worthwhile.