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: Mitre Corp
Lines: 40
Message-ID: <ghmlju$ndk$1@fred.mathworks.com>
References: <ghmkpn$9ml$1@fred.mathworks.com> <ghmlaj$inl$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 23988 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 2318
Xref: news.mathworks.com comp.soft-sys.matlab:505951


"someone" <someone@somewhere.net> wrote in message <ghmlaj$inl$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
> 
> % Write your very own little function and make it a seperate m-file:
> 
> b = MyOwnFuntion(n,m)
> a = randperm(n);
> m = min(m,n)  % some error checking
> b = a(1:m); % Choose only first m random permutations (m<n)
> 
> 
> % Now instead of:
> %b = randperm(100)(1:10);
> % use
> b = MyOwnFuntion(100,10)
> 
> 
> 
% Oops, first line shoud be:
function b = MyOwnFuntion(n,m)