Path: news.mathworks.com!not-for-mail
From: "Pithawat " <tanvach+matlab@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Do stuff without colons
Date: Tue, 9 Dec 2008 20:59:02 +0000 (UTC)
Organization: Univ of Oxford
Lines: 39
Message-ID: <ghmm6m$7r9$1@fred.mathworks.com>
References: <ghmkpn$9ml$1@fred.mathworks.com> <ghml3n$eoe$1@fred.mathworks.com> <ghmlju$ndi$1@fred.mathworks.com>
Reply-To: "Pithawat " <tanvach+matlab@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228856342 8041 172.30.248.38 (9 Dec 2008 20:59:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Dec 2008 20:59:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 330324
Xref: news.mathworks.com comp.soft-sys.matlab:505956


"Matt" <mjacobson.removethis@xorantech.com> wrote in message <ghmlju$ndi$1@fred.mathworks.com>...
> "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.

I'm looking for a way to keep my variables in m files to minimum, this helps to make it more readable.

It's also for typing inside input() function call so you can do some funky stuff when asked to enter something.

But really it's because I'm very surprised MATLAB doesn't have something so simple as treating array output from a function as array. Just doesn't make sense to me.